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 -
ftpFile("upload","login","passwd","unixbox",remote,"",m_spreadName,"i");
-
-
private void ftpFile(String actionType,String user,String
-
password,String host,String remoteDirFile,String remoteFILE,String
-
localeFile,String modeType)
-
{
-
//modeType='a' for ascii || 'i' for binary
-
-
if(actionType.equalsIgnoreCase("download")) ///Download a file
-
{
-
try
-
{
-
URL url = new
-
URL("ftp://"+user+":"+password+"@"+host+".sbc.com:21/%2F"+remoteDirFile
-
+";type="+modeType);
-
-
URLConnection conn = url.openConnection();
-
-
PrintWriter ot = new PrintWriter(new FileWriter(localeFile));
-
BufferedReader in = new BufferedReader(new
-
InputStreamReader(conn.getInputStream()));
-
String line="";
-
-
while((line = in.readLine()) != null)
-
{
-
ot.println(line);
-
}
-
-
ot.close();
-
in.close();
-
-
}
-
catch (MalformedURLException m)
-
{
-
System.out.println(" Error: "+m);
-
}
-
catch (IOException ioe)
-
{
-
-
System.out.println(" Error: "+ioe);
-
String weekDay = convertToValidWeekDay(determineValidWeekDay((new GregorianCalendar().get(Calendar.DAY_OF_WEEK + day--))));
-
-
if(day < -7)
-
{
-
System.out.println(" No valid file(s) to "+actionType);
-
}
-
-
String remoteDirFile2="/production/"+weekDay+"/dir2/"+
-
remoteFILE;
-
-
//ftpFile(actionType,user,password,host,remoteDirFile2,remoteFILE,locale File,modeType);
-
}
-
}
-
else if(actionType.equalsIgnoreCase("upload")) ///Upload a file;
-
Only binary files
-
{
-
try
-
{
-
URL url = new
-
URL("ftp://"+user+":"+password+"@"+host+".sbc.com:21/%2F"+remoteDirFile
-
); //'a' for ascii and 'i' for binary
-
-
URLConnection conn = url.openConnection();
-
OutputStream os = conn.getOutputStream();
-
BufferedInputStream bis = new BufferedInputStream(new
-
FileInputStream(localeFile));
-
int number;
-
-
while((number = bis.read()) != -1)
-
{
-
os.write(number);
-
os.flush();
-
}
-
-
os.close();
-
bis.close();
-
-
}
-
catch (MalformedURLException m)
-
{
-
System.out.println(" Error: "+m);
-
}
-
catch (IOException ioe)
-
{
-
System.out.println(" Error: "+ioe);
-
}
-
}
-
}
-
1 8280
I switched the line to read: -
URL("sftp://"+user+":"+password+"@"+host+".sbc.com:21/%2F"+remoteDirFile);
-
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?
Sign in to post your reply or Sign up for a free account.
Similar topics |
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.
|
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.
-----
|
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:
|
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.
...
|
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
| |
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...
|
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)
|
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
|
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
|
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...
|
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,...
| |
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...
|
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...
|
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();...
|
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...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |
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...
| |