Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

ftp'ing in a telnet session issue 1

Status
Not open for further replies.

srigley11

Programmer
Oct 15, 2007
5
GB
Hi,
Quick question ...
I have Perl script A on server A that telnets to server B where it starts perl script B. This script amongst other tasks, ftp's to yet another server and pulls a file back to server B. The issue? When the script hits ftp->get it fails with "access denied".
Now.. if I start a telnet session from A to B manually (as on the command prompt not in a scripy, same login + password) and kick off script B.. it works perfectly.. ftps to the next server, gets the file and processes it.

Could it be because the ftp session is trying to pass the file back to server A ?

I'll post my telnet code tomorrow (don't have it to hand), its pretty much a connect, login, run "perl scriptB arg1 arg2", disconnect.

Cheers!
Steve
 
You probably need to specify the full path in your FTP statements. It won't try and pull it back to server A if it started from server B.

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
[noevil]
Travis - Those who say it cannot be done are usually interrupted by someone else doing it; Give the wrong symptoms, get the wrong solutions;
 
Yup, have full path in there...
Good to hear that it won't try and pull it back to A.

oh, also, I chmod 777 the dir its pulled to beforehand too.
 
Weird.. when you are replicating it are you typing in everything word for word the way it is in your script? i.e. if you script says /path/to/file you are typing exactly that and not cd's to /path/to and then running file? If you want to post your code we can take a look at it.

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
[noevil]
Travis - Those who say it cannot be done are usually interrupted by someone else doing it; Give the wrong symptoms, get the wrong solutions;
 
*DOH!* think you might have it... (cd'ing vs /home/user/script.pl) that sounds like something I'd do ;-)

if this was the case then yes "Access Denied" would appear.

Will check in the morning!

Many thanks!
Steve
 
nope, not what I thought it might be...

Telnet bit in script A:
my $t = new Net::Telnet (Timeout => 7200);
$t->open("SERVERB");
$t->login("myusrname", "mypwd");
my @lines=$t->cmd("cd /home/user1/");
print @lines;
@lines=$t->cmd("perl scriptb.pl arg1 arg2");
print @lines;

ftp bit in script B :
my $ftp = Net::FTP->new(HOST) or die "Couldn't connect: $@\n";

$ftp->login('username','pwd') or die $ftp->message;
print STDOUT "Login successful\n";
$ftp->binary || die "Could not set binary mode",$ftp->message;
warn "Bin mode set...";
$ftp->cwd(DIR) or print $ftp->message;
print STDOUT "cd DIR\n";
print STDOUT "copying: $filename\n";
print STDOUT "to: $localDir\n\n";
$ftp->get($filename) or die $ftp->message."failed\n";
print STDOUT "get $filename..\n";
$ftp->quit;
 
Solved it...

Lets just say... it wasn't my code at fault ;-)

*NEXT*



Thanks for the feedback folks!
 
Good job :)

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
[noevil]
Travis - Those who say it cannot be done are usually interrupted by someone else doing it; Give the wrong symptoms, get the wrong solutions;
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top