I'm having trouble using the ftpUpload() function of RCurl to upload a file to a non-existent folder in an SFTP. I want the folder to be made if its not there, using the ftp.create.missing.dirs option. Here's my code currently:
.opts <- list(ftp.create.missing.dirs=TRUE)
ftpUpload(what = "test.txt",
to "sftp://ftp.testserver.com:22/newFolder/existingfile.txt",
userpwd = paste(user, pwd, sep = ":"), .opts = opts)`
It doesn't seem to be working as I get the following error:
* Initialized password authentication
* Authentication complete
* Failed to close libssh2 file
I can upload a file to an existent folder with success, its just when the folder isn't there I get the error.
The problem seems be due the fact you are trying to create the new folder, as seen in this question: Create an remote directory using SFTP / RCurl
The error can be found in Microsoft R Open git page:
case SSH_SFTP_CLOSE:
if(sshc->sftp_handle) {
rc = libssh2_sftp_close(sshc->sftp_handle);
if(rc == LIBSSH2_ERROR_EAGAIN) {
break;
}
else if(rc < 0) {
infof(data, "Failed to close libssh2 file\n");
}
sshc->sftp_handle = NULL;
}
if(sftp_scp)
Curl_safefree(sftp_scp->path);
In the code the parameter rc is related to libssh2_sftp_close function (more info here https://www.libssh2.org/libssh2_sftp_close_handle.html), that tries close the nonexistent directory, resulting in the error.
Try use curlPerform as:
curlPerform(url="ftp.xxx.xxx.xxx.xxx/";, postquote="MkDir /newFolder/", userpwd="user:pass")
Related
I've installed sbt using sdkman on wsl2 ubuntu setup. Currently sbt 1.4.2 is installed. When I try to launch it from the terminal it gives
sbt server is already booting. Create a new server? y/n (default y) if I choose n, nothing happens. If I choose y, then sbt starts. What I want to do is to be able to start sbt without that error message. Because this behaviour breaks metals on visual studio code.
I checked the sbt source code and found that the method below prints the error message - in sbt/main/src/main/scala/sbt/Main.scala
private def getSocketOrExit(
configuration: xsbti.AppConfiguration
): (Option[BootServerSocket], Option[Exit]) =
try (Some(new BootServerSocket(configuration)) -> None)
catch {
case _: ServerAlreadyBootingException
if System.console != null && !ITerminal.startedByRemoteClient =>
println("sbt server is already booting. Create a new server? y/n (default y)")
val exit = ITerminal.get.withRawInput(System.in.read) match {
case 110 => Some(Exit(1))
case _ => None
}
(None, exit)
case _: ServerAlreadyBootingException =>
if (SysProp.forceServerStart) (None, None)
else (None, Some(Exit(2)))
}
}
So, calling new BootServerSocket(configuration) throws an exception. Exception source is the method below from BootServerSocket.java;
static ServerSocket newSocket(final String sock) throws ServerAlreadyBootingException {
ServerSocket socket = null;
String name = socketName(sock);
try {
if (!isWindows) Files.deleteIfExists(Paths.get(sock));
socket =
isWindows
? new Win32NamedPipeServerSocket(name, false, Win32SecurityLevel.OWNER_DACL)
: new UnixDomainServerSocket(name);
return socket;
} catch (final IOException e) {
throw new ServerAlreadyBootingException();
}
}
I checked the isWindows method and it returns false. So the new UnixDomainServerSocket(name) part is running. And somehow it can't create a unix domain server socket. That's all I found out. Is there a way to fix this? Or is this a bug?
After moving my project files to a directory within wsl2, problem is solved. My project files were in a Windows directory before.
This code is run every day
Application app = new Application();
Package package = null;
string FilePath;
DTSEventListener EventListener = new DTSEventListener();
PackagePath = #"~\App_Data\Order ImportDev.dtsx";
FilePath = #"D:\Systems\Development System\Folder\ImportErrors.csv";
package = app.LoadPackage(Server.MapPath(PackagePath), EventListener);
DTSExecResult results = package.Execute(null,null, EventListener,null,null);
if (results == DTSExecResult.Failure)
{
foreach (DtsError local_DtsError in package.Errors)
{
body += local_DtsError.Description + " - " + local_DtsError.SubComponent;
}
using (SmtpClient SmtpHost = new SmtpClient("fghfefhfg"))
{
using (MailMessage MadeErrorsMessage = new MailMessage())
{
MadeErrorsMessage.To.Add(new MailAddress(user.Email));
MadeErrorsMessage.From = new MailAddress("xxr#xxx", "Someone");
MadeErrorsMessage.Subject = "Failed to load order(s)";
MadeErrorsMessage.Bcc.Add(new MailAddress("admin#somewhere", "Jason"));
MadeErrorsMessage.Body = body;
SmtpHost.Send(MadeErrorsMessage);
}
}
}
package.Dispose();
package = null;
Occasionally the file fails to load with the following error:
Error in Microsoft.SqlServer.Dts.Runtime.TaskHost/Execute SQL Task :
Executing the query "" failed with the following error: "External
component has thrown an exception.". Possible failure reasons:
Problems with the query, "ResultSet" property not set correctly,
parameters not set correctly, or connection not established correctly.
If i run the package manually on the server the file load without error but after this has happen the server cannot load anymore file through ASP.Net until the whole server is rebooted.
I have tried just restarting SSIS and also SQL but that doesn't work only a complete server reboot solves the problem.
I am able to perform Remote command execution and function calling in R script through Rserve in my Java application. But when my function is trying to save a dataframe in a csv file using
write.csv(MyData, file = "MyData.csv")
They MyData.csv file is not being generated, and no error is showing. when i am executing the same steps in R console, it working fine.
The Rserve is running in my local machine itself and I am using the following to connect and execute:
RConnection connection = new RConnection();
connection.eval("makecsv()")
p.s. I've omitted the "source the R script" step above
Just for reference this is my Dummy R script that I'm trying to run:
makecsv <- function(){
x<-rnorm(10)
y<-rnorm(10)
df1<-data.frame(x,y)
write.csv(df1, file = "MyData.csv")
return(df1)
}
Probably you have to use the absolute path, something like this:
write.csv(MyData, file = "/var/MyData.csv")
This can happen if your Rserve is dead. Wrapping in try-catch with proper error handling can help in debugging.
This version works for me:
import org.rosuda.REngine.*;
import org.rosuda.REngine.Rserve.*;
public class Main {
public static void main(String[] args) {
try {
RConnection c = new RConnection();
org.rosuda.REngine.REXP getwd = c.eval("getwd()");
System.out.println(getwd.asString());
c.eval("source(\"main.R\")");
c.eval("makecsv()");
c.close();
} catch (REngineException | REXPMismatchException e) {
e.printStackTrace();
}
}
}
The output is:
C:/Users/moon/Documents
Process finished with exit code 0
And in Documents folder I have the MyData.csv.
Here are 2 suggestions:
Try to parse the string to expression first by connection.eval(parse("makecsv()"))
Check the working dir by connection.eval("getwd()")
I have searched for something similar and I keep running across the FTP download answers. This is helpful information, but ultimately proving to be difficult to translate. I have found a powershell script and it works, but I am wondering if it can be tweaked for my needs. I don't have much experience with powershell scripting, but I'm trying to learn.
The need is this. I need to download and install a series of files to a remote machine, unattended. The files are distributed via email via tinyurls. I currently throw those into a .txt file, then have a powershell script read the list and download each file.
Requirements of the project and why I have turned to powershell (and not other utilities), is that these are very specialized machines. The only tools available are ones that are baked into Windows 7 embedded.
The difficulties I run into are:
The files download one at the time. I would like to grab as many downloads at the same time that the web server will allow. (usually 6)
The current script creates file names based off the tinyurl. I need the actual file name from the webserver.
Thanks in advance for any suggestions.
Below is the script I’m currently using.
# Copyright (C) 2011 by David Wright (davidwright#digitalwindfire.com)
# All Rights Reserved.
# Redistribution and use in source and binary forms, with or without
# modification or permission, are permitted.
# Additional information available at http://www.digitalwindfire.com.
$folder = "d:\downloads\"
$userAgent = "Mozilla/5.0 (Windows NT 6.1; WOW64; rv:7.0.1) Gecko/20100101 Firefox/7.0.1"
$web = New-Object System.Net.WebClient
$web.Headers.Add("user-agent", $userAgent)
Get-Content "d:\downloads\files.txt" |
Foreach-Object {
"Downloading " + $_
try {
$target = join-path $folder ([io.path]::getfilename($_))
$web.DownloadFile($_, $target)
} catch {
$_.Exception.Message
}
}
If you do the web request before you decide on file name you should be able to get the expanded path (otherwise you would have to make two web requests, one to get the extended path and one to download the file).
When I tried this, I found that the BaseResponse property of the Microsoft.PowerShell.Commands.HtmlWebResponseObject returned by the Invoke-WebRequest cmdlet had a ResponseUri property which was the extended path we are looking for.
If you get the correct response, just save the file using the name from the extended path, something like the following (this sample code does not look at HTTP response codes or similar, but expects everything to go well):
function Save-TinyUrlFile
{
PARAM (
$TinyUrl,
$DestinationFolder
)
$response = Invoke-WebRequest -Uri $TinyUrl
$filename = [System.IO.Path]::GetFileName($response.BaseResponse.ResponseUri.OriginalString)
$filepath = [System.IO.Path]::Combine($DestinationFolder, $filename)
try
{
$filestream = [System.IO.File]::Create($filepath)
$response.RawContentStream.WriteTo($filestream)
$filestream.Close()
}
finally
{
if ($filestream)
{
$filestream.Dispose();
}
}
}
This method could be called using something like the following, given that the $HOME\Documents\Temp folder exists:
Save-TinyUrlFile -TinyUrl http://tinyurl.com/ojt3lgz -DestinationFolder $HOME\Documents\Temp
On my computer, that saves a file called robots.txt, taken from a github repository, to my computer.
If you want to download many files at the same time, you could let PowerShell make this happen for you. Either use PowerShell workflows parallel functionality or simply start a Job for each url. Here's a sample on how you could do it using PowerShell Jobs:
Get-Content files.txt | Foreach {
Start-Job {
function Save-TinyUrlFile
{
PARAM (
$TinyUrl,
$DestinationFolder
)
$response = Invoke-WebRequest -Uri $TinyUrl
$filename = [System.IO.Path]::GetFileName($response.BaseResponse.ResponseUri.OriginalString)
$filepath = [System.IO.Path]::Combine($DestinationFolder, $filename)
try
{
$filestream = [System.IO.File]::Create($filepath)
$response.RawContentStream.WriteTo($filestream)
$filestream.Close()
}
finally
{
if ($filestream)
{
$filestream.Dispose();
}
}
}
Save-TinyUrlFile -TinyUrl $args[0] -DestinationFolder $args[1]
} -ArgumentList $_, "$HOME\documents\temp"
}
I'm trying to use PHPExcel, and it's throwing an error for even the most basic things, and even for a script copied from somewhere ( http://blog.clock.co.uk/phpexcel-example/ ).
<br />
<b>Warning</b>: Invalid argument supplied for foreach() in <b>/home/.../public_html/pear/PEAR/PHPExcel/PHPExcel/Calculation.php</b> on line <b>1685</b><br />
The outputted file has this as the very top of the file, for which Excel (or Open Office) says is not a valid file. If I remove those two lines, everything is fine and Excel (or OO) can open it with no problems and everything the script does is there.
Calculation.php line 1685:
foreach (glob($localeFileDirectory.'/*',GLOB_ONLYDIR) as $filename) {
And the function it is in:
private function __construct() {
$localeFileDirectory = PHPEXCEL_ROOT.'PHPExcel/locale/';
foreach (glob($localeFileDirectory.'/*',GLOB_ONLYDIR) as $filename) {
$filename = substr($filename,strlen($localeFileDirectory)+1);
if ($filename != 'en') {
self::$_validLocaleLanguages[] = $filename;
}
}
$setPrecision = (PHP_INT_SIZE == 4) ? 12 : 16;
$this->_savedPrecision = ini_get('precision');
if ($this->_savedPrecision < $setPrecision) {
ini_set('precision',$setPrecision);
}
} // function __construct()
I installed PHPExcel via PEAR.
I didn't see a "locale" directory anywhere in the PHPExcel setup, so I tried creating it but still have the same problem.
I'm not setting or using a locale feature.
It would appear then that there is a problem in the PEAR installation of PHPExcel, which I'll need to investigate.
You can find the locale directory and files in the source repository on github (https://github.com/PHPOffice/PHPExcel/tree/master/Classes) or in the standard zip distributions; but it would probably be better to use the full zip installation in case there are any other problems with the PEAR instal
I met this problem in PHP 5.3 + PHPExcelv1.7.6(2011-02-27) .
I solved this by updating to PHPExcel v1.8.0(2014-03-02)