Simple command line sftp client

Bill Smith bsmith@tridium.com
Mon, 2 Dec 2002 09:11:36 -0500


Bert,

Unfortunately no, I haven't received any response. I've been playing =
with a small
client that I have been working on that handles all the basic sftp =
functionality.
It's pretty rough at the moment. I can handle the following commands: =
put, mkdir,
rm, rmdir. It seems to work ok. I had to work around a couple of bugs =
(like the=20
one mentioned below). Currently it uses username/password validation and =
it works
in that if an invalid combination is provided, an exception is thrown. =
However, I
still haven't figured out how to handle the condition where the client =
must have a
valid key from the server. The mindterm pieces that helped me are:

com.mindbright.ssh2.SSH2SFTPClient.java
com.mindbright.ssh2.SSH2SFTPTransfer.java
com.mindbright.ssh2.SSH2SimpleSFTPShell.java

I think there were a couple of others, but I don't recall.

If I get a chance to clean up my code, I'll send it to you.=20

Bill

-----Original Message-----
From: Bertrand Pasquero [mailto:bpasqu@cs.mcgill.ca]
Sent: Friday, November 29, 2002 9:55 PM
To: Bill Smith
Subject: Re: Simple command line sftp client


=3D=3D=3D=3D=3D=3D=3D=3D
Hi there,

I basically have the same questions as you do (how to use the API to
transfer files using SFTP). Did you get any kind of answer? Or did you =
find
a correct way of transferring files?

Please let me know, as I am having trouble figuring out all that =
uncommented
code.

Thanks,

Bert
(CS Student, McGill University, Canada)
=3D=3D=3D=3D=3D=3D=3D=3D

----- Original Message -----
From: "Bill Smith" <bsmith@tridium.com>
To: <mindterm-users@appgate.com>
Sent: Thursday, November 21, 2002 11:10 AM
Subject: Simple command line sftp client


First, thanks for those who helped me get the mindterm src to compile.

Second, I'm looking to add sftp client functionality to a small console =
app.
(Specifically,
I'm creating an ant sftp task, for those familiar with ant). Is there an
example
for doing simple sftp functions like copyTo or copyFrom? I've included a
quick and
dirty test that I came up with, but I don't know if it's the correct
approach.

A couple of additional questions/comments.

1) If the host key from the target server isn't present on the local
machine, how can
   I identify that? With the code below, it just keeps on trucking. I'd =
like
the ability
   to accept/reject based on the existence of the key, and optionally =
copy
it down.

2) With the copyToRemote method, I noticed a small problem. For the =
second
argument you
   can pass null (based on looking at the SSH2SFTPTransfer code). When =
it's
null, the method
   fills in "." for you. The problem is in the name of the file on the
remote end. With the
   code below, and the second arg as null, the name of the file on the
remote end becomes
   ".test.txt". This seems like a bug.


Thx,
Bill

------------------------------------

import java.io.*;
import java.net.*;
import com.mindbright.ssh2.*;
import com.mindbright.util.*;
import com.mindbright.sshcommon.*;

public class Sftp
{
  public static void main(String[] argv) throws Exception
  {
    System.out.println("+Socket");
    Socket socket =3D new Socket("localhost", 22);
    System.out.println("  - " + socket);

    System.out.println("+SSH2Transport");
    SSH2Transport transport =3D new SSH2Transport(socket, new
SecureRandomAndPad());

    System.out.println("+SSH2SimpleClient");
    SSH2SimpleClient client =3D new SSH2SimpleClient(transport, "name",
"password");

    File cwd =3D new File(".");
    String[] files =3D {"test.txt"};

    System.out.println("+SSH2FTPTransfer");
    SSH2SFTPTransfer trans =3D new SSH2SFTPTransfer(cwd,
client.getConnection());
    trans.setProgress(new SSHSCPStdoutProgress());
    trans.copyToRemote(files, "./", false);
  }
}

_______________________________________________
Mindterm-users mailing list
Mindterm-users@mindterm.appgate.com
http://www.mindbright.se/mailman/listinfo/mindterm-users