473,396 Members | 1,866 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

ftp vs sftp in JAVA

112 100+
I was hoping you could help me out with ftp vs sftp.
Below is a method that I have that I call to ftp files from one unix box
to another in house, but soon, we will have to ftp from here to NY so we
have to start using sftp. I know that we have open ssh on our unix
boxes but was wondering how different the syntax would be, going from
ftp to sftp.


Here is a method that I have written in my java code for ftping a file
to a specific location.
How can I change this so that it will sftp instead of ftp?
Do I need to change this line frome ftp to sftp and thats it:
URL("ftp://"+user+":"+password+"@"+host+".sbc.com:21/%2F"+remoteDirFile

Expand|Select|Wrap|Line Numbers
  1. ftpFile("upload","login","passwd","unixbox",remote,"",m_spreadName,"i");
  2.  
Expand|Select|Wrap|Line Numbers
  1. private void ftpFile(String actionType,String user,String
  2. password,String host,String remoteDirFile,String remoteFILE,String
  3. localeFile,String modeType)
  4.     {
  5.      //modeType='a' for ascii || 'i' for binary
  6.  
  7.       if(actionType.equalsIgnoreCase("download"))  ///Download a file
  8.       {
  9.        try
  10.        {
  11.           URL url = new
  12.  URL("ftp://"+user+":"+password+"@"+host+".sbc.com:21/%2F"+remoteDirFile
  13.  +";type="+modeType);
  14.  
  15.           URLConnection conn = url.openConnection();
  16.  
  17.           PrintWriter ot = new PrintWriter(new FileWriter(localeFile));
  18.           BufferedReader in = new BufferedReader(new
  19. InputStreamReader(conn.getInputStream()));
  20.           String line="";
  21.  
  22.           while((line = in.readLine()) != null)
  23.           {
  24.               ot.println(line);
  25.           }
  26.  
  27.         ot.close();
  28.         in.close();
  29.  
  30.        }
  31.        catch (MalformedURLException m)
  32.        {
  33.           System.out.println(" Error: "+m);
  34.        }
  35.        catch (IOException ioe)
  36.        {
  37.  
  38.          System.out.println(" Error: "+ioe);
  39.          String weekDay = convertToValidWeekDay(determineValidWeekDay((new GregorianCalendar().get(Calendar.DAY_OF_WEEK + day--))));
  40.  
  41.          if(day < -7)
  42.          {
  43.            System.out.println(" No valid file(s) to "+actionType);
  44.          }
  45.  
  46.          String remoteDirFile2="/production/"+weekDay+"/dir2/"+
  47.  remoteFILE;
  48.  
  49. //ftpFile(actionType,user,password,host,remoteDirFile2,remoteFILE,locale File,modeType);
  50.        }
  51.       }
  52.      else if(actionType.equalsIgnoreCase("upload"))  ///Upload a file;
  53. Only binary files
  54.       {
  55.         try
  56.         {
  57.             URL url = new
  58. URL("ftp://"+user+":"+password+"@"+host+".sbc.com:21/%2F"+remoteDirFile
  59. ); //'a' for ascii and 'i' for binary
  60.  
  61.             URLConnection conn = url.openConnection();
  62.             OutputStream os = conn.getOutputStream();
  63.             BufferedInputStream bis =  new BufferedInputStream(new
  64. FileInputStream(localeFile));
  65.             int number;
  66.  
  67.             while((number = bis.read()) != -1)
  68.             {
  69.               os.write(number);
  70.               os.flush();
  71.             }
  72.  
  73.             os.close();
  74.             bis.close();
  75.  
  76.        }
  77.        catch (MalformedURLException m)
  78.        {
  79.          System.out.println(" Error: "+m);
  80.        }
  81.        catch (IOException ioe)
  82.        {
  83.           System.out.println(" Error: "+ioe);
  84.        }
  85.       }
  86.     }
  87.  
Nov 17 '09 #1
1 8247
ndedhia1
112 100+
I switched the line to read:


Expand|Select|Wrap|Line Numbers
  1. URL("sftp://"+user+":"+password+"@"+host+".sbc.com:21/%2F"+remoteDirFile);
  2.  
fyi..i switched the ftp:// to sftp://..

and it jumps to this exception:

Error: java.net.MalformedURLException: unknown protocol: sftp



Am I missing some import statements at the top or something?



This is in the JavaDocs:

Protocol handlers for the following protocols are guaranteed to exist on the search path :-

http, https, ftp, file, and jar


How Do I get sftp to be known as a known protocol?
Nov 17 '09 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

3
by: Gus M. Creces | last post by:
Hi... I'm looking for some information, technical, white paper - whatever - on how SFTP works. I need to add SFTP capabilities into an app's present FTP capabilities. I'm not really looking for a...
4
by: Luke Vogel | last post by:
I've looked everywhere ... Is there anywhere that has the source code for a SFTP client that I can modify for my needs? Please? -- Regards Luke. -----
0
by: Bernhard Günther | last post by:
Hello friends of php, PhP-Version is 4 on a FreeBSD-System using apache. Got a problem using ssh2.sftp. Installed correctly (libssh2, ssh2.so-module). Connecting with publickey works,...
7
by: RadhakrishnanR | last post by:
How i can implement SFTP in VB. Scenario is I want to take file from SFTP server, then after some process with the file , file will be moved to database.. Our requirement is very clear that how...
12
by: jcor | last post by:
Hi, I'm using Ubuntu 7.04. I'm writing a sript that sends files via ftp for several destinations. So far I used Net::FTP and it worked fine. My problem is that I need to send files via SFTP...
0
by: arkascha | last post by:
Helloooo everyone, I have a problem with a small solution I made some three or four years ago. Worked flawless until deployed onto newer machines now and guess what, I cannot fix it. Maybe some...
4
by: sa6113 | last post by:
I want to use sftp from paramiko to copy a file from a windows machine to a Linux in the network, I use this code : host = "LinuxComputerName" (or its Ip) port = 22 transport =...
7
by: K Viltersten | last post by:
As i noticed, there's no built-in facility for working with SFTP in DotNet. So, i'd like to learn how to build that up. When i went googling for knowledge, i only get a ton of hits on tutorials...
2
by: sivashanmugam | last post by:
Hi Friends, I tried to send some zips from local to remote location but the transfer is not sucess i can transfer the zips partially can some one assist me how to make it as sucess i had...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.