C
cartercc
I'm writing a class that will connect to and download an ASCII file via
FTP. I currently do this manually, but am automating the process. I've
reached a sticking point, and have not been able to progress for
several days, and would very much appreciate any (and all) suggestions.
The local machine is a Fedora machine and the remote machine is an AIX
machine. I have no control over the remote machine except to connect to
it and download a file.
FIRST ---------------------------
when I ftp the file manually, this is what the session looks like.
[root@serctamfedora java-bin]# ftp 9.9.9.9
Connected to 9.9.9.9
220 datatel FTP server (Version 4.1 Tue Jul 6 21:20:07 CDT 2004) ready.
502 authentication type cannot be set to GSSAPI
502 authentication type cannot be set to KERBEROS_V4
KERBEROS_V4 rejected as an authentication type
Name (9.9.9.9:root): username
331 Password required for username.
Password:
230-Last unsuccessful login: Mon Jul 31 08:59:55 CDT 2006 on ftp from
::ffff:9.9.9.8
230-Last login: Fri Aug 25 09:20:13 CDT 2006 on ftp from ::ffff:9.9.9.7
230 User username logged in.
Remote system type is UNIX.
Using binary mode to transfer files.
ftp> cd /cdata/collive/_HOLD_
250 CWD command successful.
ftp> get CCC.SER.PROGRAMS
local: CCC.SER.PROGRAMS remote: CCC.SER.PROGRAMS
227 Entering Passive Mode (9,9,9,9,139,242)
150 Opening data connection for CCC.SER.PROGRAMS (241643 bytes).
226 Transfer complete.
241643 bytes received in 3 seconds (78 Kbytes/s)
ftp> bye
[root@serctamfedora java-bin]#
SECOND ---------------------------
I've written a perl script that automates this process. Here is the
perl script. This works!!
1 #!/usr/bin/perl
2
3 use strict;
4 use Net::FTP;
5
6 my ($username, $password, $holdfile, $newname);
7
8 # Step 1 -- obtain ftp arguments: username, password, holdfile,
newname
9 print "Enter Datatel username: ";
10 $username = <STDIN>;
11 chomp $username;
12
13 print "Enter password: ";
14 $password = <STDIN>;
15 chomp $password;
16
17 print "Enter name of hold file: ";
18 $holdfile = <STDIN>;
19 chomp $holdfile;
20
21 ($newname = $holdfile) =~ s/\./_/g;
22 $newname .= '.txt';
23
24 # Step 2 -- FTP to server and download the holdfile
25 my $ftp = Net::FTP->new("9.9.9.9", Debug => 0) or die "Cannot
connect to Datatel, $@";
26 $ftp->login($username, $password) or die "Cannot login to Datatel ",
$ftp-> message;
27 $ftp->cwd("/cdata/collive/_HOLD_") or die "Cannot change working
directory to /cdata/collive/_HOLD_ ", $ftp->message;
28 $ftp->ascii;
29 $ftp->get($holdfile) or die "Cannot get $holdfile ", $ftp->message;
30 $ftp->quit;
31
32 # Step 3 -- rename the local file replacing dots with underscores
and adding '.txt' extension
33 rename $holdfile, $newname;
34
35 # Step 4 -- Miller time!
36 exit();
THIRD----------------------------------
here is the Java class file.
[root@serctamfedora java-bin]# vi TestFtp1.java
1 import java.io.*;
2 import java.lang.*;
3 import java.net.*;
4 import org.apache.commons.net.ftp.*;
5
6
7 public class TestFtp1
8 {
9 public static void main(String[] args) throws IOException
10 {
11 FTPClient ftp = new FTPClient();
12 String reply;
13 boolean success;
14 OutputStream out = new
FileOutputStream("downloadfile.txt");
15
16 try
17 {
18 ftp.connect("9.9.9.9");
19 reply = ftp.getReplyString();
20 System.out.println(reply);
21
22 ftp.login("username","password");
23 reply = ftp.getReplyString();
24 System.out.println(reply);
25
26 //ftp.setFileType(FTP.ASCII_FILE_TYPE);
27 //reply = ftp.getReplyString();
28 //System.out.println(reply);
29
30 ftp.enterRemotePassiveMode();
31 reply = ftp.getReplyString();
32 System.out.println(reply);
33
34 ftp.changeWorkingDirectory("/dir/subdir/_HOLD_");
35 reply = ftp.getReplyString();
36 System.out.println(reply);
37
38 reply = ftp.printWorkingDirectory();
39 System.out.println(reply);
40
41 success = ftp.retrieveFile("CCC.SER.PROGRAMS",out);
42 reply = ftp.getReplyString();
43 System.out.println(reply);
"TestFtp1.java" 62L, 1465C
FOURTH---------------------------------
here is the output when I run the Java application.
[root@serctamfedora java-bin]# java TestFtp1
220 datatel FTP server (Version 4.1 Tue Jul 6 21:20:07 CDT 2004) ready.
230-Last unsuccessful login: Thu Aug 24 09:52:47 CDT 2006 on
/dev/pts/63 from 9.9.9.7
230-Last login: Fri Aug 25 10:11:55 CDT 2006 on ftp from ::ffff:9.9.9.6
230 User username logged in.
227 Entering Passive Mode (9,9,9,9,139,234)
250 CWD command successful.
/cdata/collive/_HOLD_
org.apache.commons.net.io.ToNetASCIIOutputStream@a62fc3
257 "/cdata/collive/_HOLD_" is current directory.
The value of success is false
Ftp client is not connected.
QUESTION---------------------------
Does anyone have an idea as to what I am doing wrong or what can make
this work? I'm probably doing something real stupid, but for the life
of me I can't figure out what it is.
If you have an FTP class that I can use and that work, I would
appreciate it very much if you would tell me where I can get it.
CC
FTP. I currently do this manually, but am automating the process. I've
reached a sticking point, and have not been able to progress for
several days, and would very much appreciate any (and all) suggestions.
The local machine is a Fedora machine and the remote machine is an AIX
machine. I have no control over the remote machine except to connect to
it and download a file.
FIRST ---------------------------
when I ftp the file manually, this is what the session looks like.
[root@serctamfedora java-bin]# ftp 9.9.9.9
Connected to 9.9.9.9
220 datatel FTP server (Version 4.1 Tue Jul 6 21:20:07 CDT 2004) ready.
502 authentication type cannot be set to GSSAPI
502 authentication type cannot be set to KERBEROS_V4
KERBEROS_V4 rejected as an authentication type
Name (9.9.9.9:root): username
331 Password required for username.
Password:
230-Last unsuccessful login: Mon Jul 31 08:59:55 CDT 2006 on ftp from
::ffff:9.9.9.8
230-Last login: Fri Aug 25 09:20:13 CDT 2006 on ftp from ::ffff:9.9.9.7
230 User username logged in.
Remote system type is UNIX.
Using binary mode to transfer files.
ftp> cd /cdata/collive/_HOLD_
250 CWD command successful.
ftp> get CCC.SER.PROGRAMS
local: CCC.SER.PROGRAMS remote: CCC.SER.PROGRAMS
227 Entering Passive Mode (9,9,9,9,139,242)
150 Opening data connection for CCC.SER.PROGRAMS (241643 bytes).
226 Transfer complete.
241643 bytes received in 3 seconds (78 Kbytes/s)
ftp> bye
[root@serctamfedora java-bin]#
SECOND ---------------------------
I've written a perl script that automates this process. Here is the
perl script. This works!!
1 #!/usr/bin/perl
2
3 use strict;
4 use Net::FTP;
5
6 my ($username, $password, $holdfile, $newname);
7
8 # Step 1 -- obtain ftp arguments: username, password, holdfile,
newname
9 print "Enter Datatel username: ";
10 $username = <STDIN>;
11 chomp $username;
12
13 print "Enter password: ";
14 $password = <STDIN>;
15 chomp $password;
16
17 print "Enter name of hold file: ";
18 $holdfile = <STDIN>;
19 chomp $holdfile;
20
21 ($newname = $holdfile) =~ s/\./_/g;
22 $newname .= '.txt';
23
24 # Step 2 -- FTP to server and download the holdfile
25 my $ftp = Net::FTP->new("9.9.9.9", Debug => 0) or die "Cannot
connect to Datatel, $@";
26 $ftp->login($username, $password) or die "Cannot login to Datatel ",
$ftp-> message;
27 $ftp->cwd("/cdata/collive/_HOLD_") or die "Cannot change working
directory to /cdata/collive/_HOLD_ ", $ftp->message;
28 $ftp->ascii;
29 $ftp->get($holdfile) or die "Cannot get $holdfile ", $ftp->message;
30 $ftp->quit;
31
32 # Step 3 -- rename the local file replacing dots with underscores
and adding '.txt' extension
33 rename $holdfile, $newname;
34
35 # Step 4 -- Miller time!
36 exit();
THIRD----------------------------------
here is the Java class file.
[root@serctamfedora java-bin]# vi TestFtp1.java
1 import java.io.*;
2 import java.lang.*;
3 import java.net.*;
4 import org.apache.commons.net.ftp.*;
5
6
7 public class TestFtp1
8 {
9 public static void main(String[] args) throws IOException
10 {
11 FTPClient ftp = new FTPClient();
12 String reply;
13 boolean success;
14 OutputStream out = new
FileOutputStream("downloadfile.txt");
15
16 try
17 {
18 ftp.connect("9.9.9.9");
19 reply = ftp.getReplyString();
20 System.out.println(reply);
21
22 ftp.login("username","password");
23 reply = ftp.getReplyString();
24 System.out.println(reply);
25
26 //ftp.setFileType(FTP.ASCII_FILE_TYPE);
27 //reply = ftp.getReplyString();
28 //System.out.println(reply);
29
30 ftp.enterRemotePassiveMode();
31 reply = ftp.getReplyString();
32 System.out.println(reply);
33
34 ftp.changeWorkingDirectory("/dir/subdir/_HOLD_");
35 reply = ftp.getReplyString();
36 System.out.println(reply);
37
38 reply = ftp.printWorkingDirectory();
39 System.out.println(reply);
40
41 success = ftp.retrieveFile("CCC.SER.PROGRAMS",out);
42 reply = ftp.getReplyString();
43 System.out.println(reply);
"TestFtp1.java" 62L, 1465C
FOURTH---------------------------------
here is the output when I run the Java application.
[root@serctamfedora java-bin]# java TestFtp1
220 datatel FTP server (Version 4.1 Tue Jul 6 21:20:07 CDT 2004) ready.
230-Last unsuccessful login: Thu Aug 24 09:52:47 CDT 2006 on
/dev/pts/63 from 9.9.9.7
230-Last login: Fri Aug 25 10:11:55 CDT 2006 on ftp from ::ffff:9.9.9.6
230 User username logged in.
227 Entering Passive Mode (9,9,9,9,139,234)
250 CWD command successful.
/cdata/collive/_HOLD_
org.apache.commons.net.io.ToNetASCIIOutputStream@a62fc3
257 "/cdata/collive/_HOLD_" is current directory.
The value of success is false
Ftp client is not connected.
QUESTION---------------------------
Does anyone have an idea as to what I am doing wrong or what can make
this work? I'm probably doing something real stupid, but for the life
of me I can't figure out what it is.
If you have an FTP class that I can use and that work, I would
appreciate it very much if you would tell me where I can get it.
CC