Solve the problem of fake death of Java FTP uploaded files

Before uploading files using FTP, the code was very stable. It has been used for nearly three years. Because of data migration, it was found that after setting up an FTP server, configuring the IP and account password, and then using the previous code:

In the process of downloading, the program pretends to be dead, that is, it neither reports an error, nor throws an exception, nor terminates. It just keeps stuck and can't locate the problem. I studied it for a long time and didn't know what happened. Later, I checked it on the Internet. Someone put forward a method that is really easy to use. Share here:

Solution:

When calling ftpclient Listfiles() or ftpclient Before the retrieveFile () method, call FTPClient.. enterLocalPassiveMode()! In other people's original words, "this method means that before each data connection, the FTP client tells the FTP server to open a port to transmit data." To tell you the truth, what does this mean? I don't quite understand it at this level. I hope you can give me some advice. Now I'll post the FTP related code and share it with you.

//Create FTP connection

ftp. Setdefaultport (/ / ftp port number);

ftp. Connect (/ / FTP service IP address);

ftp. Login (/ / ftp user name, / / password);

ftp. setBufferSize(1024);

//Set file type (binary)

ftp. setFileType(ftp.BINARY_FILE_TYPE);

//Before each data connection, the FTP client tells the FTP server to open a port to transmit data. / / after adding this line of code, there is no problem in uploading or downloading files. It seems that there is an implied bug in my code, which is embarrassing

ftp. enterLocalPassiveMode();

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>