$ cat 2.sftp1.pl #!/usr/bin/perl -w use 5.011; use Net::SFTP::Foreign; my $upload_file = shift; my $sftp = get_tiny(); my $server_dir = "perlmonks/scripts"; $sftp->mkdir("/$server_dir") or warn "mkdir1 failed $!\n"; $sftp->setcwd("/$server_dir") or warn "setcwd1 failed $!\n"; $sftp->put($upload_file) or warn "upload put failed $!\n"; my $remote_dir = $sftp->cwd; say "remote dir is $remote_dir"; my $ls = $sftp->ls( $remote_dir); print "$_->{filename}\n" for (@$ls); say "final ref to sftp object is is $sftp"; undef $sftp; sub get_tiny { use 5.011; use warnings; use Net::SFTP::Foreign; use Config::Tiny; use Data::Dumper; my $ini_path = qw( /home/bob/Documents/html_template_data/3.values.ini ); say "ini path is $ini_path"; my $sub_hash = "my_sftp"; my $Config = Config::Tiny->new; $Config = Config::Tiny->read( $ini_path, 'utf8' ); say Dumper $Config; # -> is optional between brackets my $domain = $Config->{$sub_hash}{'domain'}; my $username = $Config->{$sub_hash}{'username'}; my $password = $Config->{$sub_hash}{'password'}; my $port = $Config->{$sub_hash}{'port'}; my $key_path = $Config->{$sub_hash}{'key_path'}; #dial up the server say "values are $domain $username $password $port $key_path"; my $sftp = Net::SFTP::Foreign->new( $domain, user => $username, port => $port, # password => $password, key_path => $key_path ) or die "Can't connect: $!\n"; return $sftp; } __END__ $