Я пытаюсь подключиться к удаленному 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
Spring FTP -сервер, бросающий ответ с 450 запрашиваемым действием файла, не принятым ⇐ JAVA
Программисты JAVA общаются здесь
1738338940
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?
Подробнее здесь: [url]https://stackoverflow.com/questions/79402771/spring-ftp-throwing-server-replied-with-450-requested-file-action-not-taken[/url]
Ответить
1 сообщение
• Страница 1 из 1
Перейти
- Кемерово-IT
- ↳ Javascript
- ↳ C#
- ↳ JAVA
- ↳ Elasticsearch aggregation
- ↳ Python
- ↳ Php
- ↳ Android
- ↳ Html
- ↳ Jquery
- ↳ C++
- ↳ IOS
- ↳ CSS
- ↳ Excel
- ↳ Linux
- ↳ Apache
- ↳ MySql
- Детский мир
- Для души
- ↳ Музыкальные инструменты даром
- ↳ Печатная продукция даром
- Внешняя красота и здоровье
- ↳ Одежда и обувь для взрослых даром
- ↳ Товары для здоровья
- ↳ Физкультура и спорт
- Техника - даром!
- ↳ Автомобилистам
- ↳ Компьютерная техника
- ↳ Плиты: газовые и электрические
- ↳ Холодильники
- ↳ Стиральные машины
- ↳ Телевизоры
- ↳ Телефоны, смартфоны, плашеты
- ↳ Швейные машинки
- ↳ Прочая электроника и техника
- ↳ Фототехника
- Ремонт и интерьер
- ↳ Стройматериалы, инструмент
- ↳ Мебель и предметы интерьера даром
- ↳ Cантехника
- Другие темы
- ↳ Разное даром
- ↳ Давай меняться!
- ↳ Отдам\возьму за копеечку
- ↳ Работа и подработка в Кемерове
- ↳ Давай с тобой поговорим...
Мобильная версия