473,809 Members | 2,819 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

ftp vs sftp in JAVA

112 New Member
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+":"+pass word+"@"+host+" .sbc.com:21/%2F"+remoteDirF ile

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 8280
ndedhia1
112 New Member
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.Malfor medURLException : 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
4166
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 3rd party solution, like a plug in. Would prefer to write the code in C++ or C#. Just haven't found much technical information on the topic. Thanks in advance for any suggestions, leads in the right direction.
4
2440
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
4693
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, sftp subsystem-connect works too:
7
15423
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 to use SFTP in VB, currently we are using the OS-native FTP functionality, for SFTP there is no OS-native functionality. And we are not using any third party tool. In VB is it possible to accomplish this job.? If not could u give the reason. ...
12
15678
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 (SSH2). I've been trying to install Net::SFTP with 'sudo perl -MCPAN -e "install NET::SFTP' but I can't. It stops in the middle of the installation: Crypt-DH-0.06/t/ Crypt-DH-0.06/t/00-compile.t
0
1890
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 guru here can give this a look and tell a stupid newbie like me what I miss... The strategy is to have some kind of a shell-like wrapper and work interactively with it from my php scripts. So I setup a wrapper object and can write a command and...
4
4720
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 = paramiko.Transport((host, port)) password = "LinuxComputerPassword" username = "LinuxComputerUserName" transport.connect(username = username, password = password)
7
12300
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 for specific, already existing packages. The problem is that i'd like to learn how set up such a communication myself. Any pointers? (Please note that googling for
2
3834
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 used the below code #!/bin/sh /usr/local/bin/expect <<EOF
0
9721
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9600
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10376
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
9198
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
6880
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5548
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5686
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
3860
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
3011
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.