Topic "File name not valid, can you explain what is the issue?"

Author Message
Philky001
[View user's profile]
Donor
Joined: 2015-11-24
Posts: 20
the path is indeed correct. what is not liking here?

-------Program Starts Running----------
-------Session instance successfully Created.----------
All File Paths are downloaded.
Looping for BESTBUYDS
File Path \\SERVER-APP02\ARCUST\IBS\DATA\ORDERS\BESTBYDS\
Error:WinSCP.SessionRemoteException: Error listing directory '\\SERVER-APP02\ARCUST\IBS\DATA\ORDERS\BESTBYDS\'. ---> WinSCP.SessionRemoteException: The filename is not valid.
Error code: 20
Error message from server: Invalid path /\\SERVER-APP02\ARCUST\IBS\DATA\ORDERS\BESTBYDS\
--- End of inner exception stack trace ---
Advertisements
martin
[View user's profile]
Site Admin
Joined: 2002-12-10
Posts: 24555
Location: Prague, Czechia
You have the paths wrong somehow.
Either you use local path instead of remote path.
Or the path syntax is wrong. You generally cannot use UNC path syntax for a remote path.

So what is \\SERVER-APP02\ARCUST\IBS\DATA\ORDERS\BESTBYDS\ ? Is it local (or a locally accessible network path) or remote path?
Philky001
[View user's profile]
Donor
Joined: 2015-11-24
Posts: 20
Server app02 is our server. But i think the code is calling this remote. ah but before we were successful using a mapped path T:\
but the thing is we get this path from a table so dont have to hard code. I guess i can test using a mapped path to see if that is the cause.
martin
[View user's profile]
Site Admin
Joined: 2002-12-10
Posts: 24555
Location: Prague, Czechia
Do you mean that the "app02" is the remote (FTP or SFTP) server?

So why do you use SFTP or FTP, if you can access the files directly over UNC path?

I probably still do not understand, what are you trying to do.
Philky001
[View user's profile]
Donor
Joined: 2015-11-24
Posts: 20
app02 is our server where we want to place the orders gotten from ecomm site.

we using SFTP because we were doing manually before and wanted to automate.
martin
[View user's profile]
Site Admin
Joined: 2002-12-10
Posts: 24555
Location: Prague, Czechia
OK, so it's a "local path".

That means you have probably swapped "local" and "remote" arguments in some call (probably GetFiles or SynchronizeDirectories).

Show us your code or log file (Session.SessionLogPath), ideally both.
Philky001
[View user's profile]
Donor
Joined: 2015-11-24
Posts: 20
this is the program.cs

Code:
using System;
using System.Collections.Generic;
using System.Configuration;
using System.Globalization;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using WinSCP;

namespace SFTPGetConsole
{
    class Program
    {
        public static int Main()
        {
            try
            {
                Helper.AddtoLogFile("-------Program Starts Running----------");
                // Setup session options
                SessionOptions sessionOptions = new SessionOptions
                {
                    Protocol = Protocol.Sftp,
                    HostName = ConfigurationManager.AppSettings["HostName"].ToString(),
                    UserName = ConfigurationManager.AppSettings["UserName"].ToString(),
                    Password = ConfigurationManager.AppSettings["Password"].ToString(),
                    SshHostKeyFingerprint = ConfigurationManager.AppSettings["SshHostKeyFingerprint"].ToString()
                };

                using (Session session = new Session())
                {
                    // Connect
                    session.Open(sessionOptions);
                    Helper.AddtoLogFile("-------Session instance successfully Created.----------");
                    List<vw_importSFTP> ImportFilePaths = DBProvider.Instance.DownloadParameters();
                    Helper.AddtoLogFile("All File Paths are downloaded.");
                    foreach (vw_importSFTP item in ImportFilePaths)
                    {
                        if (!string.IsNullOrEmpty(item.FolderName))
                        {
                            try
                            {
                                Helper.AddtoLogFile("Looping for " + item.gImportID);
                                Helper.AddtoLogFile("File Path " + item.filePath);
                                //RemoteDirectoryInfo directory = session.ListDirectory(ConfigurationManager.AppSettings["RemotePath"].ToString());
                                RemoteDirectoryInfo directory = session.ListDirectory(item.filePath);
                                foreach (RemoteFileInfo fileInfo in directory.Files)
                                {
                                    Console.WriteLine("{0} with size {1}, permissions {2} and last modification at {3}",
                                        fileInfo.Name, fileInfo.Length, fileInfo.FilePermissions, fileInfo.LastWriteTime);

                                    string fileName = fileInfo.Name;
                                    //string remotePath = ConfigurationManager.AppSettings["RemotePath"].ToString() + fileName;
                                    string remotePath = item.filePath + fileName;
                                    string FolderName = "";
                                    if (string.IsNullOrEmpty(item.FolderName))
                                    {
                                        FolderName = "Others";
                                    }
                                    if (Directory.Exists(ConfigurationManager.AppSettings["LocalPath"].ToString() + "//" + FolderName))
                                    {
                                        Directory.CreateDirectory(ConfigurationManager.AppSettings["LocalPath"].ToString() + "//" + FolderName);
                                    }
                                    //Local Path
                                    string localPath = ConfigurationManager.AppSettings["LocalPath"].ToString() + "//" + FolderName + "//" + fileName;
                                    Helper.AddtoLogFile("Local Path " + localPath);
                                    Console.WriteLine("Local Path " + localPath);

                                    if (session.FileExists(remotePath))
                                    {
                                        bool download;
                                        if (!File.Exists(localPath))
                                        {
                                            Console.WriteLine("File {0} exists, local backup {1} does not", remotePath, localPath);
                                            Helper.AddtoLogFile(string.Format("File {0} exists, local backup {1} does not", remotePath, localPath));
                                            download = true;
                                        }
                                        else
                                        {
                                            DateTime remoteWriteTime = session.GetFileInfo(remotePath).LastWriteTime;
                                            DateTime localWriteTime = File.GetLastWriteTime(localPath);

                                            if (remoteWriteTime > localWriteTime)
                                            {
                                                Console.WriteLine(
                                                    "File {0} as well as local backup {1} exist, " +
                                                    "but remote file is newer ({2}) than local backup ({3})",
                                                    remotePath, localPath, remoteWriteTime, localWriteTime);
                                                download = true;
                                            }
                                            else
                                            {
                                                Console.WriteLine(
                                                    "File {0} as well as local backup {1} exist, " +
                                                    "but remote file is not newer ({2}) than local backup ({3})",
                                                    remotePath, localPath, remoteWriteTime, localWriteTime);
                                                download = false;
                                            }
                                        }

                                        if (download)
                                        {
                                            // Download the file and throw on any error
                                            session.GetFiles(remotePath, localPath).Check();

                                            Console.WriteLine("Download to backup done.");
                                            Helper.AddtoLogFile("Download to backup done.");
                                        }
                                    }
                                    else
                                    {
                                        Console.WriteLine("File {0} does not exist yet", remotePath);
                                    }

                                }

                            }
                            catch (Exception ex) { Helper.AddtoLogFile("Error:" + ex.ToString()); }
                        }
                    }
                }
Philky001
[View user's profile]
Donor
Joined: 2015-11-24
Posts: 20
this is the log i have

-------Program Starts Running----------
-------Session instance successfully Created.----------
All File Paths are downloaded.
Looping for BESTBUYDS
File Path \\SERVER-APP02\ARCUST\IBS\DATA\ORDERS\BESTBYDS\
Error:WinSCP.SessionRemoteException: Error listing directory '\\SERVER-APP02\ARCUST\IBS\DATA\ORDERS\BESTBYDS\'. ---> WinSCP.SessionRemoteException:

The filename is not valid.
Error code: 20
Error message from server: Invalid path /\\SERVER-APP02\ARCUST\IBS\DATA\ORDERS\BESTBYDS\


--- End of inner exception stack trace ---
at WinSCP.SessionLogReader.Read(LogReadFlags flags)
at WinSCP.ElementLogReader.Read(LogReadFlags flags)
at WinSCP.SessionElementLogReader.Read(LogReadFlags flags)
at WinSCP.ElementLogReader.Read(LogReadFlags flags)
at WinSCP.CustomLogReader.TryWaitForNonEmptyElement(String localName, LogReadFlags flags)
at WinSCP.CustomLogReader.WaitForNonEmptyElement(String localName, LogReadFlags flags)
at WinSCP.CustomLogReader.WaitForNonEmptyElementAndCreateLogReader(String localName, LogReadFlags flags)
at WinSCP.Session.ListDirectory(String path)
at SFTPGetConsole.Program.Main() in \\fs1\userdata\philk\My Documents\SFTP1\SFTPGetConsole\SFTPGetConsole\Program.cs:line 46
Looping for Walmart.com
martin
[View user's profile]
Site Admin
Joined: 2002-12-10
Posts: 24555
Location: Prague, Czechia
You must have a local path (the \\SERVER-APP02\ARCUST\...) in [ConfigurationManager.AppSettings["RemotePath"].

So this call fails:
session.ListDirectory(ConfigurationManager.AppSettings["RemotePath"].ToString());
Philky001
[View user's profile]
Donor
Joined: 2015-11-24
Posts: 20
OK thanks we had a dummy thing there. the thing is, the local path is not fixed. it will depend on the customer. All the other values we have in app settings are fixed.

<add key="LocalPath" value="E:\SFTP_FILES\" />

like for walmart it will be \\acust02\walmart

for best buy it will be \\arcust02\bestbuy

so do we need it must be a fixed spot say \\arcust\orders

then we need to parse in a separate process?
martin
[View user's profile]
Site Admin
Joined: 2002-12-10
Posts: 24555
Location: Prague, Czechia
I wrote about RemotePath, you respond with a comment on LocalPath. I'm getting lost.
Advertisements

You can post new topics in this forum






Search Site

What is WinSCP?

It is award-winning SFTP client, SCP client, FTPS client and FTP client integrated into one software program for file transfer to FTP server or secure SFTP server. [More]

And it's free!

Donate

About donations

$9   $19   $49   $99

About donations

Recommend

WinSCP Privacy Policy

WinSCP License