Я сталкиваюсь с проблемой, когда кажется, что мое FTP-соединение правильное и ошибки не получены, но файл не помещен на FTP-сервер.
Я использую commons-net-ftp.
Код:
int retCode = 0;
FTPClient client = new FTPClient();
client.addProtocolCommandListener(new PrintCommandListener(new PrintWriter(System.out)));
InputStream input = null;
try
{
int replyCode;
client.connect(pHostName);
replyCode = client.getReplyCode();
if (!FTPReply.isPositiveCompletion(replyCode))
{
client.disconnect();
logInfo("ftpFile() - FTP Server refused connection");
retCode = 1;
}
else
{
if(client.login(pUserName, pPassword))
{
//default is FTP.ASCII_FILE_TYPE
if(this.isBinaryTransfer())
{
client.setFileType(FTP.BINARY_FILE_TYPE);
}
// Use passive mode as default because most of us are
// behind firewalls these days.
client.enterLocalPassiveMode();
input = new FileInputStream(pLocalFileName);
if(this.isRemoveRemoteFile())
{
client.deleteFile(pRemoteFileName);
client.getReply();
this.logReplyStringInfo(client.getReplyStrings(), "Removing Remote File");
}
if(this.isOverwriteFile())
{
replyCode = client.sendCommand("-O");
this.logReplyStringInfo(client.getReplyStrings(), "Overwrite File");
}
if(!client.storeFile(pRemoteFileName, input))
{
logError("ftpFile() - Not able to store the file on the server" );
retCode = 6;
}
input.close();
client.logout();
client.disconnect();
}
else
{
client.logout();
client.disconnect();
retCode = 3;
}
}
}
catch (FileNotFoundException fileNotFoundException)
{
logError("ftpFile(String, String, String, String, String)", fileNotFoundException); //$NON-NLS-1$
fileNotFoundException.printStackTrace();
retCode = 5;
}
catch (FTPConnectionClosedException e)
{
logError("ftpFile(String, String, String, String, String)", e); //$NON-NLS-1$
retCode = 4;
e.printStackTrace();
}
catch (IOException e)
{
logError("ftpFile(String, String, String, String, String)", e); //$NON-NLS-1$
e.printStackTrace();
e.printStackTrace();
retCode = 2;
}
finally
{
if (client.isConnected())
{
try
{
if(null != input)
{
input.close();
}
client.disconnect();
}
catch (IOException f)
{
logWarning("ftpFile(String, String, String, String, String) - exception ignored", f); //$NON-NLS-1$
}
}
}
Трассировка файла журнала:
2010-10-12 10: 57: 53,527 ИНФОРМАЦИЯ [STDOUT] 230 Успешный вход в систему
2010-10-12 10: 57: 53 527 INFO [STDOUT] PASV
2010-10-12 10: 57: 53 576 INFO [STDOUT] 227 Вход в пассивный режим (216,27,89,17,10,231)
2010-10-12 10: 57: 53,624 ИНФОРМАЦИЯ [STDOUT] STOR SharperImageFeed2.txt
2010-10-12 10: 57: 53,681 ИНФО [STDOUT] 150 "/SharperImageFeed2.txt" файл готов к приему в режиме ASCII
2010-10-12 10: 57: 54,337 ИНФОРМАЦИЯ [STDOUT] 226 Передача успешно завершена.
2010-10-12 10: 57: 54,337 ИНФОРМАЦИЯ [STDOUT] ВЫЙТИ
2010-10-12 10:57: 54,384 ИНФОРМАЦИЯ [STDOUT] 221 Windows FTP-сервер (WFTPD, Texas Imperial Software) прощается
Есть предложения по поводу проблемы?Любой тест, который можно запустить?
Я могу ftp и загрузить файл с помощью FileZilla.
При дальнейшем тестировании я могу выполнить успешную установку FTP, когда я запускаю из своего локальногоdev env - это Windows (Eclipse / JBoss) Но когда FTP запускается с рабочего сервера (Linux / JBoss) Трассировка указывает, что он успешен, но на FTP-сервере ничего не размещено.