rbnorthcutt has asked for the wisdom of the Perl Monks concerning the following question:

im trying to copy a directory on a remote machine. basically just renaming it on the remote machine. for some reason it will not let me do this saying that the "cp" is missing the destination file. my code follows...
# Creates path to home directory $homedir = "/var/www/localhost/htdocs/$user_name"; # Sets user directroy path $last_user_dir = "/var/www/localhost/htdocs/$last_user_name"; # Start of ssh my $ssh_conn=Net::SSH::Perl->new( $ssh_host, debug => 3, protocol => +'2'); $ssh_conn->login( $ssh_user, $ssh_pass ); ($stdout, $stderr, $exit) = $ssh_conn->cmd( "cp -r $last_user_dir $hom +edir"); $ssh_conn->cmd( "rm -r $last_user_dir" ); $ssh_conn->cmd( "exit" );
debug output
dns1: Reading configuration data /root/.ssh/config dns1: Reading configuration data /etc/ssh_config dns1: Allocated local port 1023. dns1: Connecting to primerib.otelco.net, port 22. dns1: Remote protocol version 2.0, remote software version OpenSSH_4.2 dns1: Net::SSH::Perl Version 1.29, protocol version 2.0. dns1: No compat match: OpenSSH_4.2. dns1: Connection established. dns1: Sent key-exchange init (KEXINIT), wait response. dns1: Algorithms, c->s: 3des-cbc hmac-sha1 none dns1: Algorithms, s->c: 3des-cbc hmac-sha1 none dns1: Entering Diffie-Hellman Group 1 key exchange. dns1: Sent DH public key, waiting for reply. dns1: Received host key, type 'ssh-dss'. dns1: Host 'primerib.otelco.net' is known and matches the host key. dns1: Computing shared secret key. dns1: Verifying server signature. dns1: Waiting for NEWKEYS message. dns1: Enabling incoming encryption/MAC/compression. dns1: Send NEWKEYS, enable outgoing encryption/MAC/compression. dns1: Sending request for user-authentication service. dns1: Service accepted: ssh-userauth. dns1: Trying empty user-authentication request. dns1: Authentication methods that can continue: publickey,password,key +board-interactive. dns1: Next method to try is publickey. dns1: Trying pubkey authentication with key file '/root/.ssh/id_dsa' dns1: Authentication methods that can continue: publickey,password,key +board-interactive. dns1: Next method to try is publickey. dns1: Next method to try is password. dns1: Trying password authentication. dns1: Login completed, opening dummy shell channel. dns1: channel 0: new [client-session] dns1: Requesting channel_open for channel 0. dns1: channel 0: open confirm rwindow 0 rmax 32768 dns1: Got channel open confirmation, requesting shell. dns1: Requesting service shell on channel 0. dns1: channel 1: new [client-session] dns1: Requesting channel_open for channel 1. dns1: Entering interactive session. dns1: Sending command: cp -r /var/www/localhost/htdocs/bnorthct /var/www/localhost/htdocs/test dns1: Requesting service exec on channel 1. dns1: channel 1: open confirm rwindow 0 rmax 32768 dns1: channel 1: rcvd eof dns1: channel 1: output open -> drain dns1: input_channel_request: rtype exit-status reply 0 dns1: channel 1: rcvd close dns1: channel 1: input open -> closed dns1: channel 1: close_read dns1: channel 1: obuf empty dns1: channel 1: output drain -> closed dns1: channel 1: close_write dns1: channel 1: send close dns1: channel 1: full closed dns1: channel 2: new [client-session] dns1: Requesting channel_open for channel 2. dns1: Entering interactive session. dns1: Sending command: rm -r /var/www/localhost/htdocs/bnorthct dns1: Requesting service exec on channel 2. dns1: channel 2: open confirm rwindow 0 rmax 32768 dns1: channel 2: rcvd eof dns1: channel 2: output open -> drain dns1: input_channel_request: rtype exit-status reply 0 dns1: channel 2: rcvd close dns1: channel 2: input open -> closed dns1: channel 2: close_read dns1: channel 2: obuf empty dns1: channel 2: output drain -> closed dns1: channel 2: close_write dns1: channel 2: send close dns1: channel 2: full closed dns1: channel 3: new [client-session] dns1: Requesting channel_open for channel 3. dns1: Entering interactive session. dns1: Sending command: exit dns1: Requesting service exec on channel 3. dns1: channel 3: open confirm rwindow 0 rmax 32768 dns1: channel 3: rcvd eof dns1: channel 3: output open -> drain dns1: input_channel_request: rtype exit-status reply 0 dns1: channel 3: rcvd close dns1: channel 3: input open -> closed dns1: channel 3: close_read dns1: channel 3: obuf empty dns1: channel 3: output drain -> closed dns1: channel 3: close_write dns1: channel 3: send close dns1: channel 3: full closed cp: missing destination file Try `cp --help' for more information. bash: line 1: /var/www/localhost/htdocs/test: No such file or director +y
i can provide more if needed. thank you for any help or pointing in the right direction.

Edited by planetscape - added readmore tags

( keep:0 edit:14 reap:0 )

Replies are listed 'Best First'.
Re: Net::SSH::Perl remote copying issues
by Fletch (Bishop) on Aug 22, 2006 at 18:27 UTC

    Looks like you've got a newline on the end of something ($user_name or $last_user_name, or both). You need to chomp things before you try and use them.

      kodo's to you. thank you so much. i cant believe you could see that with out all the code present. i was not chomping the last user name at input. thank you so much. ive been beating myself up on this for days.
Re: Net::SSH::Perl remote copying issues
by traveler (Parson) on Aug 22, 2006 at 18:43 UTC
    It is likely that on the target system with cp -r the detination directory must exist. (Added: Also all components of the path must exist regardless of the system: does at least /var/www/localhost/htdocs exist?) It appears that /var/www/localhost/htdocs/test does not. You can use mkdir to create it.