gpt4 book ai didi

java - Proftpd - 上传后的 0kb 文件

转载 作者:太空宇宙 更新时间:2023-11-04 14:15:39 36 4
gpt4 key购买 nike

我找了很久也没找到解决办法。我正在尝试将文件从我的计算机上传到我的 ftp 服务器。但每次我尝试时,我都只创建一个 0kb 文件。

我已经尝试过

  1. 关闭防火墙
  2. 在文件夹上执行 chmod -R 775
  3. 20 个不同版本的客户端
  4. 被动传输模式
  5. 二进制文件类型
  6. 二进制类型传输模式
  7. 使用最新的 commons-net 库 (3.3)

相关:

0 kb file created once FTP is done in java

FTP a file to server, but it the result arrives with zero byte size

public static void goforIt(){
FTPClient ftpClient = new FTPClient();
ftpClient.addProtocolCommandListener(new PrintCommandListener(new PrintWriter(System.out)));
try {

ftpClient.connect("xxx.xxx.xxx.xx");

ftpClient.login("xx", "xx");
ftpClient.setFileType(FTP.BINARY_FILE_TYPE);
//ftpClient.setFileTransferMode(FTP.BINARY_FILE_TYPE);
ftpClient.enterLocalPassiveMode();
boolean w = ftpClient.changeWorkingDirectory("/var/www/xx");


if (ftpClient.getReplyString().contains("250")) {
InputStream in = null;
try{
in = new FileInputStream(new File("xx.mp4"));
}catch (Exception e){
e.printStackTrace();
return;
}

ftpClient.sendCommand("PWD");


boolean result = ftpClient.storeFile("/var/www/public_videos/xx.mp4", in);
System.out.println(ftpClient.getReplyString() + result);

in.close();
ftpClient.logout();
ftpClient.disconnect();
}

} catch (SocketException e) {
e.printStackTrace();
} catch (UnknownHostException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
}

日志:

220 ProFTPD 1.3.4a Server (Debian) [::ffff:xx.xxx.xx.xx]
USER xx
331 Password required for xx
PASS xx
230 User xx logged in
TYPE I
200 Type set to I
CWD /var/www/xx
250 CWD command successful
PWD
257 "/var/www/xx" is the current directory
PASV
227 Entering Passive Mode (xx,xx,xx,xxx,xxx,xx).
STOR /var/www/public_videos/xx.mp4
150 Opening BINARY mode data connection for /var/www/xx/xx.mp4
226 Transfer complete
226 Transfer complete
true
QUIT
221 Goodbye.

结果:

http://puu.sh/e6pVx/051c175f9e.png

最佳答案

删除

ftpClient.enterLocalPassiveMode();

解决我的问题

关于java - Proftpd - 上传后的 0kb 文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27780478/

36 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com