Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/323.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/azure/13.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 使用commons net 3.0 api(org.apache.commons.net)在ftp服务器上上载文件时出现问题_Java_Ftp_Apache Commons Net - Fatal编程技术网

Java 使用commons net 3.0 api(org.apache.commons.net)在ftp服务器上上载文件时出现问题

Java 使用commons net 3.0 api(org.apache.commons.net)在ftp服务器上上载文件时出现问题,java,ftp,apache-commons-net,Java,Ftp,Apache Commons Net,我正在尝试将文本文件保存在ftp服务器上,该服务器位于我的驱动器中,它有数据,文件已成功存储在那里,但该文件即使有数据也完全为空 以下是我松散的尝试 FTPClient client = new FTPClient(); FileInputStream fis = null; try { client.connect("ftp.drivehq.com"); } catch (SocketException e) { // TODO Au

我正在尝试将文本文件保存在ftp服务器上,该服务器位于我的驱动器中,它有数据,文件已成功存储在那里,但该文件即使有数据也完全为空

以下是我松散的尝试

FTPClient client = new FTPClient();
    FileInputStream fis = null;


    try {
        client.connect("ftp.drivehq.com");
    } catch (SocketException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    } catch (IOException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
    try {
        client.login("zaheerkth", "mypassword");
    } catch (IOException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }

    String filename = "c://ss.txt";
    try {
        fis = new FileInputStream(filename);
    } catch (FileNotFoundException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
    try {
        client.storeFile(filename, fis);
    } catch (IOException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
    try {
        client.logout();
    } catch (IOException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
    try {
        fis.close();
    } catch (IOException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
  }

如果在防火墙或NAT后面运行,可能需要执行
client.enterLocalPassiveMode()


编辑:本地被动可能是您想要的。

如果您在防火墙或NAT后面运行,您可能需要执行
客户端。输入localpassiveMode()


编辑:本地被动可能是您想要的。

这是我的代码,请检查此代码。我想将文件名存储在数据库中,并将文件存储在ftp服务器中。在此代码中,我可以存储文件。该文件中没有内容,它将作为空白文件存储

     String email="";    
     int i=0;    

 int count1=0;
     boolean isMultipart = ServletFileUpload.isMultipartContent(request);
     if (!isMultipart) {
      } else {
   FileItemFactory factory = new DiskFileItemFactory();
   ServletFileUpload upload = new ServletFileUpload(factory);
   List items = null;
   try {
   items = upload.parseRequest(request);
   } catch (FileUploadException e) {
   e.printStackTrace();
   }
   Iterator itr = items.iterator();
   while (itr.hasNext()) 
   {
   FileItem item = (FileItem) itr.next();
   if (item.isFormField())
   {
      String name = item.getFieldName();
      String value = item.getString();
      if(name.equals("email"))
           {
           email=value;
                }




     } else
   {
     try {

     String itemName = item.getName();
     itemName = new java.io.File(itemName).getName(); 

     String fname="";
     String ext="";
     int mid= itemName.lastIndexOf(".");
     fname=itemName.substring(0,mid);
     ext=itemName.substring(mid+1,itemName.length()); 

     if(ext.equals("doc") || ext.equals("docx") ||ext.equals("txt")    ||ext.equals("pdf")){  
     count1=1;
     FileInputStream fis = null;


    Class.forName("com.mysql.jdbc.Driver");
                Connection conn = DriverManager.getConnection("jdbc:mysql://localhost:3306/beehivej_beehivejobs", "root", "root");
                Statement stmt = conn.createStatement();
                String s="SELECT idfile FROM file ORDER BY idfile DESC LIMIT 1";
                ResultSet rs=stmt.executeQuery(s);
                while(rs.next()){i=Integer.parseInt(rs.getString(1));}
                String sql="insert into file (filename,emailid) Values ('"+itemName+"','"+email+"')";
                int in=stmt.executeUpdate(sql);

      FTPClient client = new FTPClient();

      try {

      client.connect("ftp.xyz.com");

      } catch (SocketException e) {
      // TODO Auto-generated catch block
      e.printStackTrace();
      } catch (IOException e) {
      // TODO Auto-generated catch block
      e.printStackTrace();
      }
      try {
      client.login("username", "password");


      } catch (IOException e) {
      // TODO Auto-generated catch block
      e.printStackTrace();
      }


      try {
      fis = new FileInputStream(itemName);
      count1=1;
      } catch (FileNotFoundException e) {
        // TODO Auto-generated catch block
      e.printStackTrace();
      }
      try {

      String name="Beehive_Resume"+i+"."+ext;
      client.enterLocalPassiveMode();
      client.storeFile(itemName, fis);

     count1=1;
     } catch (IOException e) {
    // TODO Auto-generated catch block
    e.printStackTrace();
     }
    try {
    client.enterLocalActiveMode();
    client.logout();
    count1=1;
    } catch (IOException e) {
    // TODO Auto-generated catch block
    e.printStackTrace();
    }
    try {
    fis.close();
    count1=1;
    } catch (IOException e) {
    // TODO Auto-generated catch block
    e.printStackTrace();
    }


    }else
    {
      response.sendRedirect("Account/reg4.jsp?email="+email+"&msg=This is not Supported  File");
    }
    }catch (Exception e) {
    e.printStackTrace();
    count1=1;
    }
    }
    } 
    }
    if(count1==1)
    {
     response.sendRedirect("Account/Home.jsp?email="+email);
    }

这是我的代码,请在这里签入。我想在数据库中存储文件名,在ftp服务器中存储文件。在这段代码中,我可以存储文件。该文件中没有内容,它存储为空白文件

     String email="";    
     int i=0;    

 int count1=0;
     boolean isMultipart = ServletFileUpload.isMultipartContent(request);
     if (!isMultipart) {
      } else {
   FileItemFactory factory = new DiskFileItemFactory();
   ServletFileUpload upload = new ServletFileUpload(factory);
   List items = null;
   try {
   items = upload.parseRequest(request);
   } catch (FileUploadException e) {
   e.printStackTrace();
   }
   Iterator itr = items.iterator();
   while (itr.hasNext()) 
   {
   FileItem item = (FileItem) itr.next();
   if (item.isFormField())
   {
      String name = item.getFieldName();
      String value = item.getString();
      if(name.equals("email"))
           {
           email=value;
                }




     } else
   {
     try {

     String itemName = item.getName();
     itemName = new java.io.File(itemName).getName(); 

     String fname="";
     String ext="";
     int mid= itemName.lastIndexOf(".");
     fname=itemName.substring(0,mid);
     ext=itemName.substring(mid+1,itemName.length()); 

     if(ext.equals("doc") || ext.equals("docx") ||ext.equals("txt")    ||ext.equals("pdf")){  
     count1=1;
     FileInputStream fis = null;


    Class.forName("com.mysql.jdbc.Driver");
                Connection conn = DriverManager.getConnection("jdbc:mysql://localhost:3306/beehivej_beehivejobs", "root", "root");
                Statement stmt = conn.createStatement();
                String s="SELECT idfile FROM file ORDER BY idfile DESC LIMIT 1";
                ResultSet rs=stmt.executeQuery(s);
                while(rs.next()){i=Integer.parseInt(rs.getString(1));}
                String sql="insert into file (filename,emailid) Values ('"+itemName+"','"+email+"')";
                int in=stmt.executeUpdate(sql);

      FTPClient client = new FTPClient();

      try {

      client.connect("ftp.xyz.com");

      } catch (SocketException e) {
      // TODO Auto-generated catch block
      e.printStackTrace();
      } catch (IOException e) {
      // TODO Auto-generated catch block
      e.printStackTrace();
      }
      try {
      client.login("username", "password");


      } catch (IOException e) {
      // TODO Auto-generated catch block
      e.printStackTrace();
      }


      try {
      fis = new FileInputStream(itemName);
      count1=1;
      } catch (FileNotFoundException e) {
        // TODO Auto-generated catch block
      e.printStackTrace();
      }
      try {

      String name="Beehive_Resume"+i+"."+ext;
      client.enterLocalPassiveMode();
      client.storeFile(itemName, fis);

     count1=1;
     } catch (IOException e) {
    // TODO Auto-generated catch block
    e.printStackTrace();
     }
    try {
    client.enterLocalActiveMode();
    client.logout();
    count1=1;
    } catch (IOException e) {
    // TODO Auto-generated catch block
    e.printStackTrace();
    }
    try {
    fis.close();
    count1=1;
    } catch (IOException e) {
    // TODO Auto-generated catch block
    e.printStackTrace();
    }


    }else
    {
      response.sendRedirect("Account/reg4.jsp?email="+email+"&msg=This is not Supported  File");
    }
    }catch (Exception e) {
    e.printStackTrace();
    count1=1;
    }
    }
    } 
    }
    if(count1==1)
    {
     response.sendRedirect("Account/Home.jsp?email="+email);
    }

谢谢你。它是有效的:)。所以我得到了一个解决方案,在3天后上传一个文件:(:他应该把那个电话放在哪里?在你打电话给
storeFile
之前打电话给他,它应该可以工作,假设你没有任何其他网络问题。谢谢。它可以工作:)。所以我得到了一个解决方案,在3天后上传一个文件:(:他应该把那个电话放在哪里?在你打电话给
storeFile
之前打电话给他,它应该可以工作,假设你没有任何其他网络问题。