//ftp上传文件
private void ftpUpload(String filePath,String fileName) {
String serverName = "192.168.99.6";
String userName = "trayton//ftpguest";
String passWord = " QwH@iAE7861";
TelnetOutputStream os = null;
FileInputStream fis = null;
FtpClient fc = null;
try {
fc = new FtpClient(serverName);
fc.login(userName, passWord);
fc.cd("test");
fc.binary();//二进制上传文件
os = fc.put(fileName);
File file = new File(filePath);
if(file.length()==0) return;
fis = new FileInputStream(file);
byte bytes[] = new byte[1024];
int c;
while((c=fis.read(bytes))!=-1)
os.write(bytes,0,c);
if(fis!=null) fis.close();
if(os!=null) os.close();
}catch (IOException ex) {
JOptionPane.showMessageDialog(this,"上传文件失败! "+fileName);
ex.printStackTrace();
return;
}finally{
try{
if (fis != null) fis.close();
if (os != null) os.close();
}catch(Exception exc){
exc.printStackTrace();
}
}
}
private void ftpUpload(String filePath,String fileName) {
String serverName = "192.168.99.6";
String userName = "trayton//ftpguest";
String passWord = " QwH@iAE7861";
TelnetOutputStream os = null;
FileInputStream fis = null;
FtpClient fc = null;
try {
fc = new FtpClient(serverName);
fc.login(userName, passWord);
fc.cd("test");
fc.binary();//二进制上传文件
os = fc.put(fileName);
File file = new File(filePath);
if(file.length()==0) return;
fis = new FileInputStream(file);
byte bytes[] = new byte[1024];
int c;
while((c=fis.read(bytes))!=-1)
os.write(bytes,0,c);
if(fis!=null) fis.close();
if(os!=null) os.close();
}catch (IOException ex) {
JOptionPane.showMessageDialog(this,"上传文件失败! "+fileName);
ex.printStackTrace();
return;
}finally{
try{
if (fis != null) fis.close();
if (os != null) os.close();
}catch(Exception exc){
exc.printStackTrace();
}
}
}