FTPSClient仅在上传微不足道的文件时成功

时间:2018-10-26 23:32:56

标签: java file-upload ftps ftp-server

在将文件上传到FTPS服务器时,我遇到了一个严重的(怪异的)问题。

我必须上传JSON文件,其中一些确实很小(小于5kB)。这些文件没有问题,我可以成功上传它们。

但是当上传“更大”的文件(不是很大,超过30kb)时,会显示此错误:

    """
Connect to an OpenStack cloud.

For a full guide see TODO(etoews):link to docs on developer.openstack.org
"""

import argparse
import os

import openstack
from openstack.config import loader
import sys

openstack.enable_logging(True, stream=sys.stdout)

#: Defines the OpenStack Config loud key in your config file,
#: typically in $HOME/.config/openstack/clouds.yaml. That configuration
#: will determine where the examples will be run and what resource defaults
#: will be used to run the examples.
TEST_CLOUD = os.getenv('OS_TEST_CLOUD', 'devstack-admin')
config = loader.OpenStackConfig()
cloud = openstack.connect(cloud=TEST_CLOUD)


class Opts(object):
    def __init__(self, cloud_name='devstack-admin', debug=False):
        self.cloud = cloud_name
        self.debug = debug
        # Use identity v3 API for examples.
        self.identity_api_version = '3'


def _get_resource_value(resource_key, default):
    return config.get_extra_config('example').get(resource_key, default)

SERVER_NAME = 'openstacksdk-example'
IMAGE_NAME = _get_resource_value('image_name', 'cirros-0.3.5-x86_64-disk')
FLAVOR_NAME = _get_resource_value('flavor_name', 'm1.small')
NETWORK_NAME = _get_resource_value('network_name', 'private')
KEYPAIR_NAME = _get_resource_value('keypair_name', 'openstacksdk-example')
SSH_DIR = _get_resource_value(
    'ssh_dir', '{home}/.ssh'.format(home=os.path.expanduser("~")))
PRIVATE_KEYPAIR_FILE = _get_resource_value(
    'private_keypair_file', '{ssh_dir}/id_rsa.{key}'.format(
        ssh_dir=SSH_DIR, key=KEYPAIR_NAME))

EXAMPLE_IMAGE_NAME = 'openstacksdk-example-public-image'


def create_connection_from_config():
    return openstack.connect(cloud=TEST_CLOUD)


def create_connection_from_args():
    parser = argparse.ArgumentParser()
    config = loader.OpenStackConfig()
    config.register_argparse_arguments(parser, sys.argv[1:])
    args = parser.parse_args()
    return openstack.connect(config=config.get_one(argparse=args))


def create_connection(auth_url, region, project_name, username, password):

    return openstack.connect(
        auth_url=auth_url,
        project_name=project_name,
        username=username,
        password=password,
        region_name=region,
        app_name='examples',
        app_version='1.0',
    )

这是我的上传代码

java.net.SocketException: Connection reset by peer: socket write error
    at java.net.SocketOutputStream.socketWrite0(Native Method)
    at java.net.SocketOutputStream.socketWrite(Unknown Source)
    at java.net.SocketOutputStream.write(Unknown Source)
    at java.io.BufferedOutputStream.flushBuffer(Unknown Source)
    at java.io.BufferedOutputStream.flush(Unknown Source)
    at java.io.FilterOutputStream.flush(Unknown Source)
    at java.io.FilterOutputStream.close(Unknown Source)
    at org.apache.commons.net.ftp.FTPClient._storeFile(FTPClient.java:688)
    at org.apache.commons.net.ftp.FTPClient.__storeFile(FTPClient.java:639)
    at org.apache.commons.net.ftp.FTPClient.storeFile(FTPClient.java:2030)
    at com.spsa.integracion.gastosingresos.business.impl.GastosIngresosIFImpl.envioArchivoAFTPS(GastosIngresosIFImpl.java:206)
    at com.spsa.integracion.gastosingresos.business.impl.GastosIngresosIFImpl.ejecutar(GastosIngresosIFImpl.java:90)
    at com.spsa.integracion.gastosingresos.GastosIngresosApplication.run(GastosIngresosApplication.java:27)
    at org.springframework.boot.SpringApplication.callRunner(SpringApplication.java:800)
    at org.springframework.boot.SpringApplication.callRunners(SpringApplication.java:784)
    at org.springframework.boot.SpringApplication.run(SpringApplication.java:338)
    at com.spsa.integracion.gastosingresos.GastosIngresosApplication.main(GastosIngresosApplication.java:20)
    Suppressed: java.net.SocketException: Software caused connection abort: socket write error
        at java.net.SocketOutputStream.socketWrite0(Native Method)
        at java.net.SocketOutputStream.socketWrite(Unknown Source)
        at java.net.SocketOutputStream.write(Unknown Source)
        at java.io.BufferedOutputStream.flushBuffer(Unknown Source)
        at java.io.BufferedOutputStream.flush(Unknown Source)
        at java.io.FilterOutputStream.close(Unknown Source)
        ... 11 more

我已经尝试过outpustream,但遇到了同样的错误。还尝试使用WinSCP手动上传,并且可以正常工作,因此这不是权限问题。

1 个答案:

答案 0 :(得分:0)

我设法解决了这个问题。发生的情况是FTPS服务器正在使用SSL v3协议进行连接,并且由于某些安全漏洞,java弃用了该协议。

最好的解决方案是更改FTP服务器的协议