如何上传文件到驱动HQ [英] How to upload file to drive HQ

查看:108
本文介绍了如何上传文件到驱动HQ的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Exception in thread "main" java.net.ConnectException: Connection timed out: connect
	at java.net.TwoStacksPlainSocketImpl.socketConnect(Native Method)
	at java.net.AbstractPlainSocketImpl.doConnect(Unknown Source)
	at java.net.AbstractPlainSocketImpl.connectToAddress(Unknown Source)
	at java.net.AbstractPlainSocketImpl.connect(Unknown Source)
	at java.net.PlainSocketImpl.connect(Unknown Source)
	at java.net.SocksSocketImpl.connect(Unknown Source)
	at java.net.Socket.connect(Unknown Source)
	at java.net.Socket.connect(Unknown Source)
	at java.net.Socket.<init>(Unknown Source)
	at java.net.Socket.<init>(Unknown Source)
	at org.apache.commons.net.DefaultSocketFactory.createSocket(DefaultSocketFactory.java:53)
	at org.apache.commons.net.SocketClient.connect(SocketClient.java:162)
	at org.apache.commons.net.SocketClient.connect(SocketClient.java:250)
	at JavaClassPak.FileUpload.upload(FileUpload.java:18)
	at JavaClassPak.FileUpload.main(FileUpload.java:55)





我尝试过:





What I have tried:

package JavaClassPak;

import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.net.InetAddress;
import java.net.SocketException;

import org.apache.commons.net.ftp.FTPClient;

public class FileUpload {
	//String Ftp_Path = "ftp://173.201.0.1/";
	//String Ftp_Path = "173.201.0.1";
	FTPClient client = new FTPClient();
	public boolean upload(File file) throws SocketException, IOException{
		System.out.println("hello world");
	         client.enterLocalPassiveMode();
	            client.connect("www.ftp.drivehq.com");
                 // client.connect(Ftp_Path);
	            client.login("EmailId", "Password");
	            client.enterLocalPassiveMode();

	            FileInputStream   fis = new FileInputStream(file);

	             boolean status = client.storeFile(" \\My Documents\\"+file.getName(), fis);

	             client.logout();
	             fis.close();
				return status;

	}
public static void main(String[] args) throws SocketException, IOException {
	 /*System.out.println("Hello My World Java ");
	  InetAddress addr = InetAddress.getLocalHost();
	     
      //Getting IPAddress of localhost - getHostAddress return IP Address
      // in textual format
      String ipAddress = addr.getHostAddress();
   
      System.out.println("IP address of localhost from Java Program: " + ipAddress);
   
      //Hostname
      String hostname = addr.getHostName();
      System.out.println("Name of hostname : " + hostname);
      
      
      System.out.println();
    	System.out.println();*/
    	
    	
     
  	FileUpload obj=new FileUpload();
  	File file =new File("Helloooo.txt");
  	System.out.println(file.exists());
  	boolean b=obj.upload(file);
  	System.out.println(b);
  	
  	
/*Read more: http://javarevisited.blogspot.com/2012/09/java-program-to-find-ip-address-of.html#ixzz51IwudRt4
*/
}
}

推荐答案

引用:

线程main中的异常java.net.ConnectException:连接超时:connect

Exception in thread "main" java.net.ConnectException: Connection timed out: connect

这表明问题出在你的网络上。检查您是否可以连接到该服务,



*防火墙可以阻止您的应用或进程建立连接。

*您的流程可能不会有权限(很少)。

*服务器可能很忙。



换句话说,尝试ping服务器,看看它是不是响应。如果是,则检查您是否正确发出连接请求,否则,请仔细检查要求。我们无法调试此问题,因为它只在您的系统上可见。

That suggests that the problem is with your network. Check that you can connect to the service,

* Firewall can prevent your app or process to make connections.
* Your process may not have permissions (rarely).
* Server might be busy.

In other words, try to ping the server and see if it is responding. If it is, then check if you are making connection requests properly, otherwise, double check the requirements. We cannot debug this problem as it is only visible to you on your system.


www.ftp.drivehq.com

您确定该URL吗?

恕我直言,应该是[http(s)://] www.drivehq.com进行网络访问,或者[ftp:// ] ftp.drivehq.com用于FTP访问。

您可以验证此URL并从那里开始。
www.ftp.drivehq.com
Are you sure about that URL?
IMHO, it should be either [http(s)://]www.drivehq.com for web access, or [ftp://]ftp.drivehq.com for FTP access.
You may validate this URL and go from there.


public static  void FTPSever(String FilesFolder,String filename) throws IOException{

       System.err.println("........................."+FilesFolder+filename);


         FTPClient ftpClient = new FTPClient();
       ftpClient.connect(server, port);
              ftpClient.login(user, pass);
              ftpClient.enterLocalPassiveMode();
              ftpClient.setFileType(FTP.BINARY_FILE_TYPE);
       InputStream inputStream  =null;
          try {
           File firstLocalFile = new File(FilesFolder + filename);
              String firstRemoteFile = FilesFolder + filename;
               inputStream = new FileInputStream(firstLocalFile);

              System.out.println("Start uploading first file");
              boolean done = ftpClient.storeFile(firstRemoteFile, inputStream);

              if (done) {
                  System.out.println("The first file is uploaded successfully.");
              }

          } catch (IOException ex) {
              System.out.println("Error: " + ex.getMessage());
              ex.printStackTrace();
          }
           finally{
                  inputStream.close();
                ftpClient.logout();
               ftpClient.disconnect();
              }
   }


这篇关于如何上传文件到驱动HQ的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆