java FTP上传创建空文件 [英] java FTP upload creates empty file
本文介绍了java FTP上传创建空文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
$ b
imports *
public class ftpUpload {
public static void main(String [] args){
FTPClient ftp = new FTPClient();
int回覆;
//连接
尝试{
ftp.connect(serverAdd);
ftp.login(用户名,密码);
reply = ftp.getReplyCode();
if(FTPReply.isPositiveCompletion(reply)){
System.out.println(Connected Success ..);
//上传文件
尝试{
String fileDir =testfile.txt;
FileInputStream in = null;
in = new FileInputStream(fileDir);
ftp.storeFile(fileDir,in);
System.out.println(File upload complete ..);
} catch(IOException e){
System.out.println(e);
}
ftp.disconnect();
System.out.println(Disconnected ..);
} else {
System.out.println(Connection Failed ..);
ftp.disconnect();
}
} catch(SocketException ex){
ex.printStackTrace();
} catch(IOException ex){
ex.printStackTrace();
$ / code $ / pre
创建一个文件FTP服务器的根目录,但它是空的。怎么了?上传PDF文件时,我已经尝试将ftp模式更改为BINARY。但该文件的大小也是0。
ftp.setFileType(FTP.BINARY_FILE_TYPE);
我也只想上传一堆txt文件,所以默认的ascii模式应该没问题,对?
解决方案好的,它似乎是我的防火墙的一个探针。当我停用防火墙时,文件将被写入到ftp中,没有问题。
When I try to upload a simple text file with the apache commons ftpClient and this code:
imports*
public class ftpUpload {
public static void main(String[] args) {
FTPClient ftp = new FTPClient();
int reply;
// connect
try {
ftp.connect(serverAdd);
ftp.login(username,password);
reply = ftp.getReplyCode();
if(FTPReply.isPositiveCompletion(reply)){
System.out.println("Connected Success..");
// upload file
try {
String fileDir = "testfile.txt";
FileInputStream in = null;
in = new FileInputStream(fileDir);
ftp.storeFile(fileDir,in);
System.out.println("File upload complete..");
}catch(IOException e){
System.out.println(e);
}
ftp.disconnect();
System.out.println("Disconnected..");
}else {
System.out.println("Connection Failed..");
ftp.disconnect();
}
} catch (SocketException ex) {
ex.printStackTrace();
} catch (IOException ex) {
ex.printStackTrace();
}
}
}
A file gets created in the root of the FTP server but it is empty. what´s wrong? I already tried to change the ftp mode to BINARY when uploading a PDF file. but the file is also 0 in size.
ftp.setFileType(FTP.BINARY_FILE_TYPE);
I also only want to upload a bunch of txt files, so the default ascii mode should be fine, right?
解决方案 ok, it seems that it is a probem with my firewall. when I deactivate the firewall the file gets written to the ftp with no problem.
这篇关于java FTP上传创建空文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文