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 INFO [STDOUT] 230 正常にログインし
まし
たモード (216,27,89,17,10,231)
2010-10-12 10:57:53,624 INFO [STDOUT] STOR SharperImageFeed2.txt
2010-10-12 10:57:53,681 INFO [STDOUT] 150 "/SharperImageFeed2.txt " ファイルを ASCII モードで受信する準備ができました
2010-10-12 10:57:54,337 INFO [STDOUT] 226 転送が正常に終了しました。
2010-10-12 10:57:54,337 INFO [STDOUT] QUIT
2010-10-12 10:57:54,384 INFO [STDOUT] 221 Windows FTP サーバー (Texas Imperial Software による WFTPD) が別れを告げる
問題が何であるかについて何か提案はありますか? 実行できるテストはありますか?
FileZilla を使用してファイルを ftp およびアップロードできます。
さらにテストを行うと、ローカルの開発環境 (Windows (Eclipse/JBoss)) から実行すると、FTP プットを正常に実行できますが、FTP が本番サーバー (Linux/JBoss) から実行されると、トレースはは成功しますが、FTP サーバーには何も配置されません。