FTPClient.storeFile () a devolver o código false e FTP return é 450 e diz que o ficheiro está ocupado
o meu requisito é escrever um ficheiro para o servidor de ficheiros e para qualquer conectividade ou problemas ao escrever um ficheiro para o servidor de ficheiros, é necessário enviar um e-mail.
ao testar abaixo o código em ambiente de teste por empresa, Cliente.storeFile devolve falso para alguns ficheiros .Estamos a colocar os ficheiros manualmente no servidor de ficheiros alvo para os quais falhou ones.It não é esperado em ambiente PROD .Alguma ideia sobre qual poderá ser a razão ?
para que saibas, os testes de negócios estão a ser feitos através do upload de muitos. arquivo.
O Meu Código:
int TIMEOUT = TimeOut * 1000; //Variable to store Connection TimeOut
AbstractTrace trace = container.getTrace();
FileInputStream fis = null;
FTPClient client = new FTPClient(); //Creating a FTPClient instance
try{
FTPClientConfig conf = new FTPClientConfig(FTPClientConfig.SYST_UNIX);
conf.setDefaultDateFormatStr(Dateformat);
client.configure(conf);
try{
client.setConnectTimeout(TIMEOUT); //Setting connection timeout
client.connect(Host);// connecting to ftp server
if(!client.login(Username, Pwd)){ throw new StreamTransformationException("Authorization failed.");} //Giving credentials to login
trace.addInfo("Successfully connected to server"+client.getReplyString());
if(!client.changeWorkingDirectory(Folderpath)){ throw new StreamTransformationException("Exception occurred while changing folder path to Interface specific path.");} //Changing the current directory to required folder path
}
catch(Exception c){
throw new StreamTransformationException("Exception occured while connecting to server :" + c);
}//close brace for catch
// Create an InputStream of the file to be uploaded
String srcFilename = FileName+"_Temp"+new Date().getTime();
String targetfilename = FileName+"_"+new Date().getTime();
File Sourcefile =new File(srcFilename);
//If file doesn't exists, then create it
if(!Sourcefile.exists()){ Sourcefile.createNewFile();}
FileWriter fileWritter = new FileWriter(Sourcefile.getName(),true);
BufferedWriter bufferWritter = new BufferedWriter(fileWritter);
bufferWritter.write(Input); //Writing the Input payload to file
bufferWritter.close();
fis = new FileInputStream(Sourcefile);
boolean done = client.storeFile(targetfilename, fis); //Store file to server
fis.close();
if (done) {
trace.addInfo("!!!----File is uploaded successfully----!!!");
} else {
trace.addWarning("Upload Failed");
throw new StreamTransformationException("Failed to upload file :Please cross check..:");
} //close brace for else
client.logout();
}catch(Exception e){
try{
Properties properties = System.getProperties(); // Get system properties
properties.setProperty("mail.smtp.host",Mail_Host); // Setup mail server
//Session session = Session.getDefaultInstance(properties); // Get the default Session object.
Session session = Session.getInstance(properties); // if you get Unknown Host exception in JAVA
//Sending mail to app support folks
MimeMessage message = new MimeMessage(session); // Create a default MimeMessage object.
message.setFrom(new InternetAddress(Mail_From)); // Set From: header field of the header.
String recipients[] =Mail_To.split(";");
InternetAddress[] addressTo = new InternetAddress[recipients.length];
for (int i = 0; i < recipients.length; i++) {
addressTo[i] = new InternetAddress(recipients[i]);
}
message.setRecipients(Message.RecipientType.TO, addressTo);
//message.addRecipient(Message.RecipientType.TO,new InternetAddress(Mail_To)); // Set To: header field of the header.
message.setSubject(Mail_Subject); // Set Subject: header field
message.setText(e.getMessage()+"."+" Failed message is having field value of "+FieldName+" is "+ReturnFieldName); // Now set the actual message
Transport.send(message); // Send message
trace.addInfo("Sent alert mail to app support folks successfully");
}catch(Exception mex){
trace.addWarning("Failed to send alert mail : "+mex);
}//close brace for catch
} //close brace for catch
finally {
try {
if (fis != null) {
fis.close();
}
client.disconnect();
} catch (IOException k) {trace.addWarning("Exception while closing filestream and diconnecting"+k); }
} //close brace for finally
return "File placed successfully";
relativamente a: Venkat
1 answers
Primeiro tente encontrar o que está a receber do method storeFile ()
ftp.getReplyString()
Usar o sistema.as.println e descubra qual é o problema com FTP.