Página 1 de 1

Transferencia de archivos a través de Net::SFTP::Foreing

NotaPublicado: 2015-07-20 16:48 @742
por coltx
¿Qué tal, estimados? Necesito su ayuda, tengo el siguiente script si bien no me arroja error tampoco me realiza el copiado del archivo... Favor, su ayuda. El script es el siguiente :
Sintáxis: [ Descargar ] [ Ocultar ]
Using perl Syntax Highlighting
  1. #!/usr/bin/perl
  2.  
  3. use Net::SFTP::Foreign;
  4.  
  5. my $sftp = Net::SFTP::Foreign->new(
  6.     '$host',
  7.     user     => '$user',
  8.     password => '$password',
  9.     port     => 22,
  10.     more     => [ -o => 'PreferredAuthentications=password,keyboard-interactive,publickey' ]
  11. );
  12.  
  13. if ( not $sftp ) {
  14.  
  15.     die("Error: No Connection:$@");
  16. }
  17. elsif ( $sftp->error ) {
  18.  
  19.     die( "Connect Failed : " . $sftp->status );
  20. }
  21. else {
  22.  
  23.     if (!$sftp->put(
  24.             "archivos/prueba.txt", "inbox/prueba.txt",
  25.             resume    => 1,
  26.             copy_perm => 0,
  27.             copy_time => 0
  28.         )
  29.         ) {
  30.         print "Failed to Transfer: " . $sftp->error;
  31.     }
  32.     else {
  33.         print "Transferencia OK!!";
  34.     }
  35.  
  36. }
Coloreado en 0.002 segundos, usando GeSHi 1.0.8.4

Re: Transferencia de archivos a través de NET::SFTP::Foreing

NotaPublicado: 2015-07-20 16:56 @747
por explorer
¿Y cuál es el mensaje de error que sale con $sftp->error?

Re: Transferencia de archivos a través de NET::SFTP::Foreing

NotaPublicado: 2015-07-20 17:21 @765
por coltx
ese es el tema... que no me arroja error :(

Re: Transferencia de archivos a través de NET::SFTP::Foreing

NotaPublicado: 2015-07-20 18:19 @805
por explorer
¿Ni siquiera sale el mensaje de "Transferencia OK!!"?

Activa la opción de depurado

more => '-v'

para que veas qué es lo que está haciendo.

Re: Transferencia de archivos a través de NET::SFTP::Foreing

NotaPublicado: 2015-07-21 06:47 @324
por coltx
Sí, efectivamente, me arroja el mensaje de "Transferencia OK", pero al revisar el repositorio... no hay nada :( Le puse el -v y esto es lo que me arroja:

Sintáxis: [ Descargar ] [ Ocultar ]
Using text Syntax Highlighting
Connecting ...
OpenSSH_6.0p1 Debian-4+deb7u2, OpenSSL 1.0.1e 11 Feb 2013
debug1: Reading configuration data /etc/ssh/ssh_config
debug1: /etc/ssh/ssh_config line 19: Applying options for *
debug1: Connecting to host [85.239.10.142] port 22.
debug1: Connection established.
debug1: identity file /home/coltx/.ssh/id_rsa type -1
debug1: identity file /home/coltx/.ssh/id_rsa-cert type -1
debug1: identity file /home/coltx/.ssh/id_dsa type -1
debug1: identity file /home/coltx/.ssh/id_dsa-cert type -1
debug1: identity file /home/coltx/.ssh/id_ecdsa type -1
debug1: identity file /home/coltx/.ssh/id_ecdsa-cert type -1
debug1: Remote protocol version 2.0, remote software version Cleo VLProxy/3.2 SSH FTP server
debug1: no match: Cleo VLProxy/3.2 SSH FTP server
debug1: Enabling compatibility mode for protocol 2.0
debug1: Local version string SSH-2.0-OpenSSH_6.0p1 Debian-4+deb7u2
debug1: SSH2_MSG_KEXINIT sent
debug1: SSH2_MSG_KEXINIT received
debug1: kex: server->client aes128-ctr hmac-md5 none
debug1: kex: client->server aes128-ctr hmac-md5 none
debug1: sending SSH2_MSG_KEXDH_INIT
debug1: expecting SSH2_MSG_KEXDH_REPLY
debug1: Server host key: RSA 5d:88:b7:5a:bb:e4:7b:95:7f:ec:a4:47:ad:13:cf:65
debug1: Host 'host' is known and matches the RSA host key.
debug1: Found key in /home/coltx/.ssh/known_hosts:18
debug1: ssh_rsa_verify: signature correct
debug1: SSH2_MSG_NEWKEYS sent
debug1: expecting SSH2_MSG_NEWKEYS
debug1: SSH2_MSG_NEWKEYS received
debug1: Roaming not allowed by server
debug1: SSH2_MSG_SERVICE_REQUEST sent
debug1: SSH2_MSG_SERVICE_ACCEPT received
debug1: Authentications that can continue: keyboard-interactive,password
debug1: Next authentication method: keyboard-interactive
Password authentication
Coloreado en 0.000 segundos, usando GeSHi 1.0.8.4

Re: Transferencia de archivos a través de Net::SFTP::Foreing

NotaPublicado: 2015-07-21 08:46 @407
por explorer
No veo nada raro... excepto el 'resume => 1'.

Haz una prueba de envío, sin esa opción.

También podría ser otra causa...

Estás poniendo un archivo dentro de una carpeta inbox/.

Si es una carpeta gestionada por un sistema de correo electrónico, podría ser que ese sistema borre o mueva ese archivo al cabo de unos segundos.

Re: Transferencia de archivos a través de Net::SFTP::Foreing

NotaPublicado: 2015-07-21 10:12 @467
por coltx
explorer, has dado en el clavo: Consultando con el encargado del otro lado me dice que, efectivamente, mueve los archivos automáticamente al caer en la carpeta inbox/...

Muchas gracias por la ayuda.

Saludos.

Re: Transferencia de archivos a través de Net::SFTP::Foreing

NotaPublicado: 2016-09-22 08:40 @402
por coltx
Ahora tengo el siguiente problema y al parecer creo es por la contraseña del sFTP (carácter $). Lo he escapado con el '\' pero, de igual forma, no conecta... El script es el siguiente:

#!/usr/bin/perl

use Net::SFTP::Foreign;

my $sftp = Net::SFTP::Foreign->new('prueba.bi.prueba.com',
user => 'prueba',
password => 'prueba$ftpt3st',
port => 22,
more => [-o => 'PreferredAuthentications=password,keyboard-interactive,publickey','-vvv']);
);

if ( not $sftp ) {

die("Error: No Connection:$@");
}
elsif ( $sftp->error ) {

die( "Connect Failed : " . $sftp->status );
}
else {

if (!$sftp->put(
"archivos/prueba.txt", "inbox/prueba.txt",
resume => 1,
copy_perm => 0,
copy_time => 0
)
) {
print "Failed to Transfer: " . $sftp->error;
}
else {
print "Transferencia OK!!";
}

}


El debug en la parte final me arroja lo siguiente :

debug2: bits set: 1017/2048
debug1: sending SSH2_MSG_KEXDH_INIT
debug1: expecting SSH2_MSG_KEXDH_REPLY
debug1: Server host key: RSA 2d:22:e8:d6:35:5c:24:56:1c:ab:43:a3:59:93:6c:14
debug3: load_hostkeys: loading entries for host "prueba.bi.prueba.com" from file "/home/usuario/.ssh/known_hosts"
debug3: load_hostkeys: found key type RSA in file /home/usuario/.ssh/known_hosts:10
debug3: load_hostkeys: loaded 1 keys
debug3: load_hostkeys: loading entries for host "89.219.11.132" from file "/home/usuario/.ssh/known_hosts"
debug3: load_hostkeys: found key type RSA in file /home/usuario/.ssh/known_hosts:8
debug3: load_hostkeys: loaded 1 keys
debug1: Host 'prueba.bi.prueba.com' is known and matches the RSA host key.
debug1: Found key in /home/usuario/.ssh/known_hosts:10
Connect Failed : No connection at Proceso.pl line 24.

Muchas gracias por tu ayuda.

Re: Transferencia de archivos a través de Net::SFTP::Foreing

NotaPublicado: 2016-09-23 15:51 @702
por explorer
Pues... no tengo ni idea. Me falta información.

¿Hay algún tipo de registro de actividad en el lado del servidor?

Re: Transferencia de archivos a través de Net::SFTP::Foreing

NotaPublicado: 2016-09-26 03:23 @183
por salva
prueba con las siguientes correcciones:

Sintáxis: [ Descargar ] [ Ocultar ]
Using perl Syntax Highlighting
  1. #!/usr/bin/perl
  2.  
  3. use Net::SFTP::Foreign;
  4.  
  5. my $sftp = Net::SFTP::Foreign->new(
  6.     'prueba.bi.prueba.com',
  7.     user     => 'prueba',
  8.     password => 'prueba$ftpt3st',
  9.     port     => 22,
  10.  
  11.     # ¡el módulo ajusta PreferredAuthentications automáticamente en la mayoría de los casos!
  12.     # more => [-o => 'PreferredAuthentications=password,keyboard-interactive,publickey','-vvv']
  13.     more => ['-vvv']
  14. );
  15.  
  16. # if ( not $sftp ) {
  17.     # esto no pasa nunca, el módulo siempre devuelve un objeto
  18.     # die("Error: No Connection:$@");
  19. #}
  20. #elsif ( $sftp->error ) {
  21.  
  22. if ( $sftp->error ) {
  23.  
  24.     # lo que te interesa es $sftp->error!
  25.     # die( "Connect Failed : " . $sftp->status );
  26.     die "Connect Failed: " . $sftp->error;
  27. }
  28. else {
  29.     if (!$sftp->put(
  30.             "archivos/prueba.txt", "inbox/prueba.txt",
  31.             resume    => 1,
  32.             copy_perm => 0,
  33.             copy_time => 0
  34.         )
  35.         ) {
  36.         print "Failed to Transfer: " . $sftp->error;
  37.     }
  38.     else {
  39.         print "¡¡Transferencia OK!!";
  40.     }
  41. }
  42.  
Coloreado en 0.001 segundos, usando GeSHi 1.0.8.4


Por cierto, también puedes probar a activar el depurado de Net::SFTP::Foreign añadiendo la siguiente línea al principio de tu script:

Sintáxis: [ Descargar ] [ Ocultar ]
Using perl Syntax Highlighting
  1. $Net::SFTP::Foreign::debug = -1;
Coloreado en 0.001 segundos, usando GeSHi 1.0.8.4