文件上传不到FTP服务器

来源:8-7 后台商品图片的springmvc上传与富文本上传ftp服务器功能开发2

慕数据4154996

2019-01-18

所有软件都是在windows环境下的
1.FTP服务器的配置:
图片描述
2.Nginx的配置:
(1)nginx.conf文件


#user  nobody;
worker_processes  1;

#error_log  logs/error.log;
#error_log  logs/error.log  notice;
#error_log  logs/error.log  info;

#pid        logs/nginx.pid;


events {
    worker_connections  1024;
}


http {
    include       mime.types;
    default_type  application/octet-stream;

    #log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '
    #                  '$status $body_bytes_sent "$http_referer" '
    #                  '"$http_user_agent" "$http_x_forwarded_for"';

    #access_log  logs/access.log  main;

    sendfile        on;
    #tcp_nopush     on;

    #keepalive_timeout  0;
    keepalive_timeout  65;

    #gzip  on;

    server {
        listen       80;
        server_name  localhost;

        #charset koi8-r;

        #access_log  logs/host.access.log  main;

        location / {
            root   html;
            index  index.html index.htm;
        }

        #error_page  404              /404.html;

        # redirect server error pages to the static page /50x.html
        #
        error_page   500 502 503 504  /50x.html;
        location = /50x.html {
            root   html;
        }

        # proxy the PHP scripts to Apache listening on 127.0.0.1:80
        #
        #location ~ \.php$ {
        #    proxy_pass   http://127.0.0.1;
        #}

        # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
        #
        #location ~ \.php$ {
        #    root           html;
        #    fastcgi_pass   127.0.0.1:9000;
        #    fastcgi_index  index.php;
        #    fastcgi_param  SCRIPT_FILENAME  /scripts$fastcgi_script_name;
        #    include        fastcgi_params;
        #}

        # deny access to .htaccess files, if Apache's document root
        # concurs with nginx's one
        #
        #location ~ /\.ht {
        #    deny  all;
        #}
    }


    # another virtual host using mix of IP-, name-, and port-based configuration
    #
    #server {
    #    listen       8000;
    #    listen       somename:8080;
    #    server_name  somename  alias  another.alias;

    #    location / {
    #        root   html;
    #        index  index.html index.htm;
    #    }
    #}

    include vhost/*.conf;
    # HTTPS server
    #
    #server {
    #    listen       443 ssl;
    #    server_name  localhost;

    #    ssl_certificate      cert.pem;
    #    ssl_certificate_key  cert.key;

    #    ssl_session_cache    shared:SSL:1m;
    #    ssl_session_timeout  5m;

    #    ssl_ciphers  HIGH:!aNULL:!MD5;
    #    ssl_prefer_server_ciphers  on;

    #    location / {
    #        root   html;
    #        index  index.html index.htm;
    #    }
    #}

}

(2)image.imooc.com.conf文件

server {
    listen 80;
    autoindex off;
    server_name image.imooc.com;
    access_log c:/access.log combined;
    index index.html index.htm index.jsp index.php;
    #error_page 404 /404.html;
    if ( $query_string ~* ".*[\;'\<\>].*" ){
        return 404;
    }

    location ~ /(mmall_fe|mmall_admin_fe)/dist/view/* {
        deny all;
    }

    location / {
        root C:\ftpfile\img;
        add_header Access-Control-Allow-Origin *;
    }
}

3.我直接访问C:\ftpfile\img\QQ截图20190114201007.png,是可以访问到的,如下图所示:
图片描述
我直接访问127.0.0.1,出现nginx的欢迎界面,如下图所示:
图片描述
我访问ftp://localhost/img/,也是完全没有问题的,如下图所示:
图片描述
我访问http://image.imooc.com/QQ%E6%88%AA%E5%9B%BE20190114201007.png,也是没有问题的,如下图所示:
图片描述
4.上面写了这么多,只是想证明我的FTP服务器和Nginx都是配置正常的,下面说说我的问题。
我刚看完8-7小节,上传文件到FTP服务器失败了。
首先是index.jsp页面:
图片描述
我点击上图红框中的上传文件按钮,跳转到下图:
图片描述
我在新标签页中打开上述链接,报404错误,如下图。
图片描述
我查看我的FTP文件夹,没有上传过来,所以上图报了404错误。
图片描述
我将上图红框中的代码注释掉,想查看文件是否上传到了Tomcat对应的文件夹下,发现是上传成功的,如下图所示:
图片描述
所以我是在Tomcat上传到FTP这个过程中出现了问题,但是idea没有报任何错误信息。
图片描述
完全不知道如何解决。
我搜索过问答区类似的问题:链接描述
上面这位哥们和我遇到的问题很相似,但是我不清楚他是怎么解决的。我也试了他里面说的把下图红框中的"img"换为"",没有效果。
图片描述
上图蓝色方框内的remotePath,我不知道这个变量是做什么用的,还有后面的changeWorkingDirectory是在做什么?
提问不易,希望老师能认真解答。

写回答

1回答

geelylucky

2019-01-18

亲爱的同学,你好,我是geely老师的助教。

你有可能是在if(connectServer(this.ip,this.port,this.user,this.pwd))这段代码返回了false,导致直接返回uploaded,也就是直接返回true,这样就不会有任何异常,也就没有上传到ftp服务器上面。

0
4
慕数据4154996
非常感谢!
2019-01-21
共4条回复

从0开始 独立完成企业级Java电商网站服务端开发

前后端分离,数据库接口设计,架构设计,功能开发,上线运维

9489 学习 · 8818 问题

查看课程