Spring FTP -сервер, бросающий ответ с 450 запрашиваемым действием файла, не принятымJAVA

Программисты JAVA общаются здесь
Ответить
Anonymous
 Spring FTP -сервер, бросающий ответ с 450 запрашиваемым действием файла, не принятым

Сообщение Anonymous »

Я пытаюсь подключиться к удаленному FTP -серверу и пытаюсь загрузить файл на сервер, но я получаю эту ошибку < /p>
Failed to write to 'testfile.txt'. Server replied with: 450 Requested file action not taken
< /code>
Далее приведен мой код: < /p>
dynamicsessionFactory.java
public class DynamicFtpSessionFactory {

private final ApplicationContext context;

public DynamicFtpSessionFactory(@NonNull final ApplicationContext context) {
this.context = context;
}

public void registerFtpSessionFactory(@NonNull final String beanName,
@NonNull final String host,
final int port,
@NonNull final String username,
@NonNull final String password) {
final BeanDefinitionRegistry registry = (BeanDefinitionRegistry) ((AnnotationConfigApplicationContext) context).getBeanFactory();

final BeanDefinitionBuilder builder = BeanDefinitionBuilder.genericBeanDefinition(DefaultFtpSessionFactory.class);
builder.addPropertyValue("host", host);
builder.addPropertyValue("port", port);
builder.addPropertyValue("username", username);
builder.addPropertyValue("password", password);
builder.addPropertyValue("fileType", FTP.ASCII_FILE_TYPE);

registry.registerBeanDefinition(beanName, builder.getBeanDefinition());

// Optionally wrap in a CachingSessionFactory
final DefaultFtpSessionFactory ftpSessionFactory = (DefaultFtpSessionFactory) context.getBean(beanName);
registry.registerBeanDefinition(beanName, BeanDefinitionBuilder.genericBeanDefinition(CachingSessionFactory.class)
.addConstructorArgValue(ftpSessionFactory)
.getBeanDefinition());
}
}
< /code>
Service: < /p>
public void uploadFileForGroupId(@NonNull final String groupId, @NonNull final Resource reportFile) throws IOException {
final CachingSessionFactory session = getFtpSessionFactory(groupId);

// Upload report file to FTP server
try (InputStream inputStream = reportFile.getInputStream()) {
session.getSession().write(inputStream, reportFile.getFilename());
log.info("File {} uploaded successfully for group Id {}.", reportFile.getFilename(), groupId);
} catch (IOException e) {
log.error("Failed to upload file: ", e);
} finally {
session.getSession().close();
}
}

private CachingSessionFactory getFtpSessionFactory(@NonNull final String groupId) {
final AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext();
context.refresh(); // Initialize the context without any configuration class
final String ftpBeanName = groupId + "Caching";
if (context.containsBean(ftpBeanName)) {
return context.getBean(ftpBeanName, CachingSessionFactory.class);
}
final DynamicFtpSessionFactory dynamicFtpSessionFactory = new DynamicFtpSessionFactory(context);

final AnfDirectoryEntity anfDirectory = getFtpConnectionDetails(groupId);
dynamicFtpSessionFactory.registerFtpSessionFactory(ftpBeanName,
anfDirectory.getSftpConnection().getSftpServer(),
FTP_PORT,
anfDirectory.getSftpConnection().getSftpUser(),
anfDirectory.getSftpConnection().getSftpPassword());

return context.getBean(ftpBeanName, CachingSessionFactory.class);
}
< /code>
Я смог загрузить файл, используя команду FTP с моей машины на FTP -сервер. Итак, если я могу загрузить по команде FTP, почему не из приложения Java?

Подробнее здесь: https://stackoverflow.com/questions/794 ... -not-taken
Ответить

Быстрый ответ

Изменение регистра текста: 
Смайлики
:) :( :oops: :roll: :wink: :muza: :clever: :sorry: :angel: :read: *x)
Ещё смайлики…
   
К этому ответу прикреплено по крайней мере одно вложение.

Если вы не хотите добавлять вложения, оставьте поля пустыми.

Максимально разрешённый размер вложения: 15 МБ.

Вернуться в «JAVA»