I am not sure what I am missing, but I have FTP connection that I have to download the contents (if any). I run the following code:
connection.nlst('*.*').each do |entry|
connection.getbinaryfile(entry, downloaded_file_path)
end
The problem is when the folder is empty, it raises Net::FTPPermError Exception: 550 *: No such file or directory.. But when the folder has content, it works just fine.
I am not sure what to try, but here is some of the output to show that the connection is working:
> connection.list
["total 0"]
> connection.pwd
"/ftp/pub/Responses"
> connection.nlst
Net::FTPPermError Exception: 550 *: No such file or directory.
I would expect nlst to return an empty array, not raise an exception?
Related
def import_sql()
#
# Authtication completed
# Authenticated obj = sqladmin
#
sql_import=Google::Apis::SqladminV1beta4::ImportContext.new
sql_import.database='postgres'
sql_import.file_type ='SQL'
sql_import.import_user ='postgres'
sql_import.uri='gs://sample-bucket-name/sample.sql'
operation=sqladmin.import_instance(instance_name,sql_import)
end
I am getting an error message:
Invalid request: One and only one file path must be specified when
importing data
I have only specified one path. Not sure where this error is coming from
I want to copy the contents of a remote location file to some local file after an ssh connection has been made.
begin
ssh = Net::SSH.start("localhost", "user")
logger.info "conn successful!"
results = conn.exec!('ruby somefile "#{arguments}"')
#code to copy the contents of a.txt in remote location to local file
#IO.copy_stream (localfile, remotefile)
rescue
logger.info "error - cannot connect to host"
end
I tried using IO.copy_stream but that doesn't work. How do I go about this?
Use Net::SCP (which requires Net::SSH) to transfer files:
Net::SCP.download!("remote.host.com", "username",
"/remote/path", "/local/path",
:password => password)
More info here: https://rubygems.org/gems/net-scp
For the palette "FTP Dir", I put "D:\FullPath\MyFolder" as Directory parameter. I get the following error after deployment :
Cannot perform FTP Operation: DIR. Error Info: Unexpected reply code. Returned Code: 550. Detail Description: CWD failed. "/D:/FullPath/MyFolder": directory not found. Expected Code: 250.
The name is concat with '/' and '\' are replaces by '/'. I develop on Windows, deploy on linux server and my FTP directory is on one Windows server.
When I try to use the 'FTP Put Palette', I have the error 'Invalid Filename'
Thank you.
You should not specify the absolute directory path in the Directory parameter but the path relative to the root directory of your FTP server.
In your case, assuming the FTP root directory is D:\FullPath and you want to access MyFolder, then you should set Directory to /MyFolder.
I was having a little trouble with reading files using the FTP adapter. Several warnings and errors were found in the application log, and it basically boiled down to this message:
A stream read or write operation failed because the stream is in an error state.
Upon inspecting the log, I was surprised to find:
< 125 List started.
< BEBI 827693 24/09/14 15:53:51 *STMF mes9_ corrigido2.csv
< 250 List completed.
> TYPE I
< 200 Representation type is binary IMAGE.
> PORT 192,168,205,82,213,48
< 200 PORT subcommand request successful.
> RETR corrigido2.csv
so, there is just a single file with name mes9_ corrigido2.csv (notice the space) and BizTalk tries to retrieve a file corrigido2.csv. Is this normal behaviour?
So I was reading the documentation for the method nlst in the NET::FTP module (ruby-1.8.6). The source code displayed is
# File net/ftp.rb, line 602
def nlst(dir = nil)
cmd = "NLST"
if dir
cmd = cmd + " " + dir
end
files = []
retrlines(cmd) do |line|
files.push(line)
end
return files
end
So the command is written literally in the string cmd, executed via retrlines and the list of files is given back right?
The thing I don't understand is that on my windows ftp server there is no such command:
230 User logged in.
Remote system type is Windows_NT.
ftp> nlst
?Invalid command
ftp>
and yet the the method returns the file list. How is it possible? The source code doesn't appear to have an abstraction of some sort on the command and also the source code of retrlines doesn't have anything special (to me).
# File lib/net/ftp.rb, line 475
def retrlines(cmd) # :yield: line
synchronize do
with_binary(false) do
conn = transfercmd(cmd)
loop do
line = conn.gets
break if line == nil
yield(line.sub(/\r?\n\z/, ""), !line.match(/\n\z/).nil?)
end
conn.close
voidresp
end
end
end
I traced back the methods called to sendcmd inside transfercmd but I have no clue really.
The question is who is telling you ?Invalid command?
In this case it's the FTP client, not the server.
The client is just a front-end for commands that it implements, converting these front-end commands into proper FTP protocol command strings for the server.
What you're looking for is the nlist (not nlst) command in your client, which will issue the NLST FTP protocol command to the server.
ftp> help nlst
?Invalid help command nlst
ftp> help nlist
nlist nlist contents of remote directory
ftp>