473,386 Members | 1,706 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

rapidshare upload perl script for linux

3
Hello,
I am new at the community and newbie at programming :)
As you may know rapidshare provides a perl script for linux, to upload files at their servers.
You can find the original scripts at rapidshare news :

Expand|Select|Wrap|Line Numbers
  1. http://images.rapidshare.com/software/rsapi.pl

If you test it you will see that you can upload one file at time.
I try to modify it in that way that script can read a text file with the names of the files i want to upload.
But the script works only if there one name file at the text.
If i try with two files (lets say File Finder_48x48.png and Dashboard_128x128.png) i take this result:

Expand|Select|Wrap|Line Numbers
  1. thanos@localhost ~/rapid2 $ perl rsapiteliko.pl Unsuccessful stat on filename containing newline at rsapiteliko.pl line 52. File Finder_48x48.png Dashboard_128x128.png is empty or does not exist! 
When the text file contains only one name file it works :confused:
The script as i modified is this :


Expand|Select|Wrap|Line Numbers
  1. #!/usr/bin/perl 
  2.  
  3. # RapidShare AG OpenSource Perl Uploader V1.0. For non-commercial use only. All rights reserved.
  4. # Included: Uploading to free, collector's and premium-zone. The MD5-check after uploads checks if the upload worked.
  5. # NOT included in this version: Upload-resume via new RS API.
  6. # This is a PERL script written for experts and for coders wanting to know how to write own upload programs.
  7. # Tested under Linux and Linux only.
  8. # If you write your own upload-tools, please look at our rsapi.cgi calls. You need them to have fun.
  9. #
  10. # To upload a file, put this script on a machine with perl installed and use the following syntax:
  11. # perl rsapi.pl free mytestfile.rar        (this uploads mytestfile.rar as a free user)
  12. # perl rsapi.pl prem archive.rar 334 test  (this uploads archive.rar to the premium-zone of login 334 with password test)
  13. # perl rsapi.pl col a.rar testuser mypw    (this uploads a.rar to the collector's-zone of login testuser with password mypw)
  14. #
  15. # We will publish another version with upload resume enabled soon, but this script actually works and we actually
  16. # want you to understand how it works and upload resume would make this script even more complex.
  17.  
  18.  
  19. #Edited by 8anos
  20. #Find the original script here: http://images.rapidshare.com/software/rsapi.pl
  21.  
  22.  
  23.  
  24.  
  25. use strict;
  26. use warnings;
  27. use Digest::MD5("md5_hex");
  28. use Fcntl;
  29. use IO::Socket;
  30.  
  31. my ($x, $text, $file, $filename, $uploadpath, $size, $socket, $uploadserver, $cursize, $fh, $bufferlen, $buffer, $boundary, $header, $contentheader,
  32. $contenttail, $contentlength, $result, $maxbufsize, $md5hex, $filecontent, $size2, %key_val, $login, $password, $zone);
  33.  
  34.  
  35.  
  36. # This chapter sets some vars and parses some vars.
  37. $/ = undef;
  38. $text ="up.txt"; #This is text with the files which you want to upload
  39. open (INFO, "$text") || die("Could not open file!");
  40. my @plirof=<INFO>;
  41. close (INFO);
  42.  
  43. foreach $x (@plirof) {
  44.  
  45. $file = $x || die "Syntax: $0 <filename to upload> <free|prem|col> [login] [password]\n";
  46. $zone = 'prem'; #If you use Free Rapidshare change "prem" to free
  47. $login = 'username'; # Your username, if your previous choise is free you havent to change it
  48. $password = 'password'; #Your password σας, if your previous choise is free you havent to change it
  49. $maxbufsize = 64000;
  50. $uploadpath = "l3";
  51. $cursize = 0;
  52. $size = -s $file || die "File $file is empty or does not exist!\n";
  53. $filename = $file =~ /[\/\\]([^\/\\]+)$/ ? $1 : $file;}
  54.  
  55.  
  56.  
  57.  #This chapter checks the file and calculates the MD5HEX of the existing local file.
  58. print "File $file has $size bytes. Calculating MD5HEX...\n";
  59. open(FH, $file) || die "Unable to open file: $!\n";
  60. $filecontent = <FH>;
  61. close(FH);
  62. $md5hex = uc(md5_hex($filecontent));
  63. $size2 = length($filecontent);
  64. print "MD5HEX is $md5hex ($size2 bytes analyzed.)\n";
  65. unless ($size == $size2) { die "Strange error: $size bytes found, but only $size2 bytes analyzed?\n" }
  66.  
  67.  
  68.  
  69. # This chapter finds out which upload server is free for uploading our file by fetching (URL address blocked: See forum rules)/cgi-bin/rsapi.cgi?sub=nextuploadserver_v1
  70. if ($login and $password) { print "Trying to upload to your premium account.\n" } else { print "Uploading as a free user.\n" }
  71. print "Uploading as filename '$filename'. Getting upload server infos.\n";
  72. $socket = IO::Socket::INET->new(PeerAddr => "rapidshare.com:80") || die "Unable to open port: $!\n";
  73. print $socket qq|GET /cgi-bin/rsapi.cgi?sub=nextuploadserver_v1 HTTP/1.0\r\n\r\n|;
  74. ($uploadserver) = <$socket> =~ /\r\n\r\n(\d+)/;
  75. unless ($uploadserver) { die "Uploadserver invalid? Internal error!\n" }
  76. print "Uploading to ul$uploadserver$uploadpath.rapidshare.com\n";
  77.  
  78.  
  79.  
  80. # This chapter opens our file and the TCP socket to the upload server.
  81. foreach $x (@plirof) {
  82.  
  83. $file = $x;
  84. sysopen($fh, $file, O_RDONLY) || die "Unable to open file: $!\n";
  85. $socket = IO::Socket::INET->new(PeerAddr => "ul$uploadserver$uploadpath.rapidshare.com:80") || die "Unable to open port: $!\n";}
  86.  
  87.  
  88.  
  89. # This chapter constructs a (somewhat RFC valid) HTTP header. See how we pass rsapi_v1=1 to the server to get a program-friendly output.
  90. $boundary = "---------------------632865735RS4EVER5675865";
  91. $contentheader .= qq|$boundary\r\nContent-Disposition: form-data; name="rsapi_v1"\r\n\r\n1\r\n|;
  92.  
  93. if ($zone eq "prem" and $login and $password) {
  94.   $contentheader .= qq|$boundary\r\nContent-Disposition: form-data; name="login"\r\n\r\n$login\r\n|;
  95.   $contentheader .= qq|$boundary\r\nContent-Disposition: form-data; name="password"\r\n\r\n$password\r\n|;
  96. }
  97.  
  98. if ($zone eq "col" and $login and $password) {
  99.   $contentheader .= qq|$boundary\r\nContent-Disposition: form-data; name="freeaccountid"\r\n\r\n$login\r\n|;
  100.   $contentheader .= qq|$boundary\r\nContent-Disposition: form-data; name="password"\r\n\r\n$password\r\n|;
  101. }
  102.  
  103. $contentheader .= qq|$boundary\r\nContent-Disposition: form-data; name="filecontent"; filename="$filename"\r\n\r\n|;
  104. $contenttail = "\r\n$boundary--\r\n";
  105. $contentlength = length($contentheader) + $size + length($contenttail);
  106. $header = qq|POST /cgi-bin/upload.cgi HTTP/1.0\r\nContent-Type: multipart/form-data; boundary=$boundary\r\nContent-Length: $contentlength\r\n\r\n|;
  107.  
  108.  
  109.  
  110. #This chapter actually sends all the data, header first, to the upload server.
  111. print $socket "$header$contentheader";
  112.  
  113. while ($cursize < $size) {
  114.   $bufferlen = sysread($fh, $buffer, $maxbufsize, 0) || 0;
  115.   unless ($bufferlen) { die "Error while sending data: $!\n" }
  116.   print "$cursize of $size bytes sent.\n";
  117.   $cursize += $bufferlen;
  118.   print $socket $buffer;
  119. }
  120.  
  121. print $socket $contenttail;
  122.  
  123.  
  124.  
  125. # OK, all is sent. Now lets fetch the server's reponse and analyze it.
  126. print "All $size bytes sent to server. Fetching result:\n";
  127. ($result) = <$socket> =~ /\r\n\r\n(.+)/s;
  128. unless ($result) { die "Ooops! Did not receive any valid server results?\n" }
  129. print "$result >>> Verifying MD5...\n";
  130.  
  131. foreach (split(/\n/, $result)) {
  132.   if ($_ =~ /([^=]+)=(.+)/) { $key_val{$1} = $2 }
  133. }
  134.  
  135.  
  136.  
  137. # Now lets check if the result contains (and it should contain) the MD5HEX of the uploaded file and check if its identical to our MD5HEX.
  138. unless ($key_val{"File1.4"}) { die "Ooops! Result did not contain MD5? Maybe you entered invalid login data.\n" }
  139. if ($md5hex ne $key_val{"File1.4"}) { die qq|Upload FAILED! Your MD5HEX is $md5hex, while the uploaded file has MD5HEX $key_val{"File1.4"}!\n| }
  140. print "MD5HEX value correct. Upload completed without errors. Saving links to rsulres.txt\n\n\n";
  141.  
  142.  
  143.  
  144. # Maybe you want the links saved to a logfile? Here we go.
  145. open(O, ">>rsulres.txt");
  146. print O $result . "\n";
  147. close(O);
  148.  
  149.  
  150.  
  151. # Thats it. Have fun experimenting with this script. Now lets say...
  152. exit;
  153.  

I will be happy if anyone can help.
Thanks in advance :)
Feb 8 '07 #1
9 20862
miller
1,089 Expert 1GB
Welcome

Don't modify their script. Create a new script that will wrap around theirs and give you this increased functionality. By modifying their code you risk introducing errors, and you potentially force yourself to have to make updates again if they update their software and protocol.

Simply create a new perl script that parses a text file for file names and then simply calls the rapid script for each file individually.

If you have any problems doing this, feel free to ask here.
Feb 8 '07 #2
8anos
3

Simply create a new perl script that parses a text file for file names and then simply calls the rapid script for each file individually.

If you have any problems doing this, feel free to ask here.
Thank you for your answer.
I' ll try it. :)
Feb 8 '07 #3
8anos
3

Simply create a new perl script that parses a text file for file names and then simply calls the rapid script for each file individually.

If you have any problems doing this, feel free to ask here.
well now i need your help.

How i call the original rs script?

here is a script that makes multiple text files with file names
Expand|Select|Wrap|Line Numbers
  1.  
  2.  
  3. my ($filepath, $file3);
  4. print "Give the path of the directory\n\n ";
  5.  
  6. $filepath=<STDIN>;
  7. chop $filepath;
  8.  
  9. my $count=1;
  10. my $new1= "new1.txt";
  11.  
  12. #Open and read the directory
  13. opendir (FILEPATH, $filepath) || die "cannot open $filepath!!";
  14. while ($file3=readdir FILEPATH) {
  15.  
  16. open (NF, ">$new1");
  17. print NF "$filepath/$file3\n" ;
  18.  
  19.  
  20. close NF;
  21.  
  22.  
  23. $new1++
  24.  
  25. }
  26.  
any help?
thanks in advance :)
Feb 12 '07 #4
miller
1,089 Expert 1GB
There are lots of different methods to call another script. There's always backticks or a system call. I would recommend that you call do though

http://perldoc.perl.org/functions/do.html

Expand|Select|Wrap|Line Numbers
  1. {
  2.    local @ARGV = ("free", "$filepath/$file3"); # Set parameters
  3.    do "rsapi.pl";
  4. }
  5.  
Feb 13 '07 #5
KevinADC
4,059 Expert 2GB
[
Expand|Select|Wrap|Line Numbers
  1. {
  2.    local @ARGV = ("free", "$filepath/$file3"); # Set parameters
  3.    do "rsapi.pl";
  4. }
  5.  
Isn't that just too cool! :)
Feb 13 '07 #6
KevinADC
4,059 Expert 2GB
maybe if you comment out this line in the rsapi.pl file it will work for multiple files:

Expand|Select|Wrap|Line Numbers
  1. $/ = undef;
change it to:

Expand|Select|Wrap|Line Numbers
  1. #$/ = undef;
and chomp the array to be safe:

Expand|Select|Wrap|Line Numbers
  1. my @plirof=<INFO>;
  2. chomp(@plirof);
Feb 13 '07 #7
Im confused

Does anyone has the complete Script for multiple files upload Rapidshare???

because I read many little parts in this thread .. but not a final

Thanks !!
Nov 14 '07 #8
pnocti
1
I took the shortcut and wrapped rsapi.pl inside a bash script. I didn't want to mess with their code.

for i in *;do rsapi "$i" col username passwd;done

lame I know but it works.
Nov 16 '07 #9
Sorry for bringing it up but i really would like to know if someone has managed to make the perl script for multiple files and post it here.

thank you in advance
Jan 9 '08 #10

Sign in to post your reply or Sign up for a free account.

Similar topics

9
by: Bob Bedford | last post by:
I've a page where the user may enter some values and upload some pictures. Unfortunately, some pictures coming from digital camera are very big, and take a lot of time for uploading. I've...
0
by: DP | last post by:
(2nd post, I think my first may have been to the wrong group - sorry) Hello Perl-ers - I´m hoping I can get some help here, because I'm very lost. Don't know Perl, I'm not a programmer. And...
3
by: David F. Skoll | last post by:
Hi, I'm tearing my hair out on this one. I'm trying to embed a Perl interpreter into a C program. I need to be able to create and destroy the interpreter periodically, but will never actually...
2
by: todanrg3 | last post by:
It is possible to upload files to Rapidshare from another page?(not using Rapidshare's own form). How can i do this with PHP?
1
by: DavidA | last post by:
I have a very simple form and perl script that is to upload a jpg file. I am not familiar with the perl language but copied the code from a text book. It works fine with all browsers except IE....
9
by: Steve Poe | last post by:
I work for an animal hospital trying to use PHP to store an animal's dental x-rays to a file server. I can browse for the xray on the local desktop computer then click "Upload Image". This...
2
by: Lastknight | last post by:
hi all, i have seen a program from web that is used to upload a file from particular directory.. My problem is that they have mentioned some file directory name in the program but when i am running...
21
KevinADC
by: KevinADC | last post by:
Note: You may skip to the end of the article if all you want is the perl code. Introduction Uploading files from a local computer to a remote web server has many useful purposes, the most...
10
sagacious
by: sagacious | last post by:
Hi There.. Nice Site.. I Want to add a File Search Engine For My Upload And Download Site.. As Like As Rapidshare Search Engins.. I Mean A Search System That Will Search Files From A...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.