用我的ftp服务器上的JAVA上传后的空文件 [英] Empty file after upload with JAVA on my ftp server
问题描述
这里是我的代码函数:
pre preublic static void upload_files(String un,String pw,String ip,String f ){
try
{
FTPClient client = new FTPClient();
client.connect(ip);
client.login(un,pw);
InputStream is = new FileInputStream(f);
client.storeFile(test2,is);
is.close();
catch(Exception e){
e.printStackTrace();
$ b
f是我想要的文件的路径上传(即C:\myfile)。在编译过程中没有错误,一个文件发送到服务器,但可悲的是空(0字节)。
我也注意到,一个简单的上传需要很长的时间一些文字(大约40多岁)甚至认为我得到了一个非常好的ISP。
我事先感谢所有人谁将帮助我。
问候,
我认为这可能与文件传输模式有关。你可以设置到二进制的Trandfer模式。有时候当你用ASCII发送数据时,它会被破坏。
引用这个
https://superuser.com/questions/82726/how-to-set-binary-mode-by-default-when-ftping-to-a-remote-site
它告诉如何在FTP命令客户端中设置二进制模式。您也将在FTPClient类也有类似的规定。
刚发现我认为类似的问题是在这里回答
FTPClient - Java,上传文件
I am facing some problem while trying to upload a file on my ftp server with java. here is my code function :
public static void upload_files(String un, String pw, String ip, String f){
try
{
FTPClient client = new FTPClient();
client.connect(ip);
client.login(un,pw);
InputStream is = new FileInputStream(f);
client.storeFile("test2",is);
is.close();
} catch(Exception e) {
e.printStackTrace();
}
}
"f" is the path of the file I want to upload (ie "C:\myfile"). No error during the compilation, one file is well sent to the server, but sadly empty (0 byte).
I also noticed that it takes quite long for a simple upload of some text (around 40s) even thought I got a really good ISP.
I thank in advance all people who will help me.
Regards,
I think it could be something to do with the mode of file transfer . Can you set the trandfer mode to Binary. Some times when you sent data in ASCII it goes corrupted . Refer to this https://superuser.com/questions/82726/how-to-set-binary-mode-by-default-when-ftping-to-a-remote-site
It tells how to set binary mode in FTP Command client. You will have a similar provision in FTPClient class also.
Just found I think similar question is answered here FTPClient - Java, upload file
这篇关于用我的ftp服务器上的JAVA上传后的空文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!