Domanda

I have written a Windows Service (C#) that connects to a SFTP location, unzips a file that contains MySQL scripts and is supposed to execute those scripts to inject data into a MySQL database.

I am having trouble getting the scripts to run. Here is my process:

  • Connect to SFTP using Renci.SSHNet library
  • Create a Process that will open a command window
  • Create a line that will run mysql.exe with the appropriate parameters. Here is an example of what I'm writing to the command window:

    "C:\Program Files (x86)\MySQL\MySQL Workbench 6.0 CE\mysql.exe" --user=username --password=password1 --host=serverHostName --port=3306 --database=mysqlData < "sftp://zendto.server.com/ftp/datadump/data_2014-05-08/mysql.sql"

When running the process, I am getting the following error in the EventLog:

The filename, directory name, or volume label syntax is incorrect.

I've also tried removing the sftp qualifier from the string since I should already be connected to SFTP.

"C:\Program Files (x86)\MySQL\MySQL Workbench 6.0 CE\mysql.exe" --user=username --password=password1 --host=serverHostName --port=3306 --database=mysqlData < "/ftp/datadump/data_2014-05-08/mysql.sql"

I get a different error for this:

The system cannot find the path specified.

Can MySQL connect directly to SFTP? Or will I have to pull down the files to the server where MySQL is located first?

È stato utile?

Soluzione

Without seeing your code I can only guess.

I assume you are executing those mysql.exe commands locally.

The first error is caused by your attempt to redirect input of mysql.exe from sftp:// URL. That's not possible on Windows (actually I'm not aware of any OS where this is possible).

The second error is caused by an attempt to access remote file from a local environment.

Simply, the fact that you connected over SFTP with Renci.SSHNet does not make Process magically work over both local and remote filesystems.

If your remote MySQL database can be managed remotely (using local mysql.exe), solution is to download your MySQL scripts and use them locally.

Though if you are able to execute remote "unzip" command, you should be able to execute remote MySQL client too (instead of local Windows mysql.exe client). That would save bandwidth for downloading the script and uploading data back.

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top