Beefy Boxes and Bandwidth Generously Provided by pair Networks
We don't bite newbies here... much
 
PerlMonks  

Re^2: Sample REST request & response code

by Aldebaran (Curate)
on Sep 07, 2018 at 00:14 UTC ( [id://1221897]=note: print w/replies, xml ) Need Help??


in reply to Re: Sample REST request & response code
in thread Sample REST request & response code

hi thanos I'm interested in replicating this. Could $host be a remote website with which I currently use sftp?

#!/usr/bin/perl -w use 5.011; use Net::SFTP::Foreign; my $upload_file = shift; my %vars = ( server_dir => 'perlmonks/scripts/', image_dir => 'pmimage', ); my $rvars = \%vars; say Dumper $rvars; my $sftp = get_tiny(); my $server_dir = $vars{"server_dir"}; $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"; $sftp->ls($server_dir) or warn "can't ls $!\n"; say "return 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.i +ni ); 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'}; #dial up the server say "values are $domain $username $password $port"; my $sftp = Net::SFTP::Foreign->new( $domain, user => $username, port => $port, password => $password ) or die "Can't connect: $!\n"; return $sftp; } __END__

This is what I've been using to try to start up a conversation with a remote server and it's either not the right thing or I don't know how to script it. I looked at your repo. Can you say a few words as to what a Snippet is? Thanks,

Replies are listed 'Best First'.
Re^3: Sample REST request & response code
by thanos1983 (Parson) on Sep 07, 2018 at 08:54 UTC

    Hello Aldebaran,

    The quick answer to your question Could $host be a remote website with which I currently use sftp? is yes it can.

    The longer version and my recommendation is not to use HTTP/HTTPS to upload files. My module is a customization which in the background uses REST::Client to do all the communication.

    Further analysis why I do not recommend to use HTTP/HTTPS for uploading files?

    HTTP and HTTPS are also stateless protocols. They may require new conn +ections for each transfer, and so they may not be suitable if a large + number of files need to be transferred.

    Reference Source HTTPS or SFTP – which is best?.

    SFTP is a protocol designed for this purposes (file transfer) using SSH connections.

    If you ask my opinion I would continue using the Net::SFTP::Foreign module but with a small modification, I would use SSH keys instead of sending username and password. If you want to see a sample of code on how to use SSH keys connection Re: Net::SFTP::Foreign Password Authentication Hangs (UPDATED). There are many reasons on why to use SSH keys instead of password, the really fast answer is because it is way more secure and less communications between client/server.

    To conclude, yes it is possible to send a file through HTTP/HTTPS (SSL encryption) with the help of my module that uses REST::Client or directly modify it for your needs, but I would not recommend it unless if you did not had the ability to use SSH strictly HTTP/HTTPS.

    You also asked what is Snippet is the name that I used for the data that is send from the server.

    Let me know if you have more questions.

    BR / Thanos

    Seeking for Perl wisdom...on the process of learning...not there...yet!

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://1221897]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others studying the Monastery: (7)
As of 2024-04-19 09:35 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found